Skip to content

Commit e9c2808

Browse files
committed
fixup! src: throw on a malformed localStorage file
Keys are stored as a blob of raw uint16_t memory, so their byte order is the platform's, but the test fixture wrote them with Buffer's utf16le encoding. On AIX and s390x the stored key therefore did not match the one that localStorage.getItem() binds, so the row was not found, no value was type-checked, and the child exited 0 instead of throwing. Encode fixture keys in the platform's byte order. Signed-off-by: Trevor Burnham <trevorburnham@gmail.com> Assisted-by: Claude Opus 5
1 parent 4a1eb6f commit e9c2808

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎test/parallel/test-webstorage.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const tmpdir = require('../common/tmpdir');
88
const assert = require('node:assert');
99
const { join } = require('node:path');
1010
const { readdir } = require('node:fs/promises');
11+
const { endianness } = require('node:os');
1112
const { DatabaseSync } = require('node:sqlite');
1213
const { test, describe } = require('node:test');
1314
let cnt = 0;
@@ -193,8 +194,12 @@ describe('a malformed localStorage file throws instead of aborting', () => {
193194
return file;
194195
}
195196

196-
// Keys are stored UTF-16LE, so a real key is needed for lookups to match.
197-
const utf16 = (str) => Buffer.from(str, 'utf16le');
197+
// Keys are stored as UTF-16 code units in the platform's byte order, so a
198+
// key only matches a lookup if it is encoded the same way.
199+
const utf16 = (str) => {
200+
const buf = Buffer.from(str, 'utf16le');
201+
return endianness() === 'BE' ? buf.swap16() : buf;
202+
};
198203

199204
for (const [name, fill, expression, detail] of [
200205
[

0 commit comments

Comments
 (0)