Files
node/test/parallel/test-querystring-escape-two-byte.js
Roberto Bianchi 544340a279 querystring: precompute Latin-1 escapes
Reuse precomputed escapes for Latin-1 characters instead of joining
two byte escapes on every occurrence. This reduces repeated work
when querystring and URLSearchParams serialize these characters.

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/66756
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-05 19:25:00 +00:00

14 lines
502 B
JavaScript

'use strict';
require('../common');
const assert = require('node:assert');
const querystring = require('node:querystring');
for (let codePoint = 0x80; codePoint < 0x800; codePoint++) {
const character = String.fromCharCode(codePoint);
const input = `prefix${character}${character}/suffix`;
const expected = encodeURIComponent(input);
assert.strictEqual(querystring.escape(input), expected);
assert.strictEqual(new URLSearchParams([[input, input]]).toString(), `${expected}=${expected}`);
}