GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Large strings decoded from latin1 and then encoded to utf8 has wrong size · Issue #22728 · nodejs/node Closed Labels bufferIssues and PRs related to the buffer subsystem.confirmed-bugIssues and PRs for confirmed bugs.encodingIssues and PRs related to the TextEncoder and TextDecoder APIs. Description
Decoding a latin1 buffer larger than about 1MB to a string and encoding that string into utf-8 gives a buffer with the same number of bytes as the latin1 input even though more are required for characters that use more space in utf-8. This seems to work properly on v10.x but not v8.x or v9.x. Code that demonstrates the problem: const fs = require('fs'); const s = 'Räksmörgås'; let ss = ''; const SIZE = (1024 * 1024); // works: //const SIZE = (1024 * 512); while (ss.length < SIZE) { ss = ss + ss.length + ' ' + s + '\n'; } // create latin1 buffer we can decode let l1Buffer = Buffer.from(ss, 'latin1'); let l1String = l1Buffer.toString('latin1') // also fixes it: // l1String = ('x' + l1String).substring(1, l1String.length + 1); // create utf8 buffer from decoded latin1 string let u8Buffer = Buffer.from(l1String, 'utf8') console.log(l1Buffer.length); console.log(u8Buffer.length); if (l1Buffer.length === u8Buffer.length) { console.log('failed, should be different size'); } else { console.log('works'); } Activity
MetadataMetadataAssigneesLabelsbufferIssues and PRs related to the buffer subsystem.confirmed-bugIssues and PRs for confirmed bugs.encodingIssues and PRs related to the TextEncoder and TextDecoder APIs. TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |