node/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js
James M Snell 548439a530
doc: doc and test URLSearchParams discrepancy
The WHATWG URL spec is not going to change this behavior so
let's document it

Signed-off-by: James M Snell <jasnell@gmail.com>

Fixes: https://github.com/nodejs/node/issues/33037

PR-URL: https://github.com/nodejs/node/pull/33236
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2020-05-06 10:40:10 -07:00

28 lines
706 B
JavaScript

'use strict';
// Tests below are not from WPT.
require('../common');
const assert = require('assert');
const URLSearchParams = require('url').URLSearchParams;
{
const params = new URLSearchParams();
assert.throws(() => {
params.toString.call(undefined);
}, {
code: 'ERR_INVALID_THIS',
name: 'TypeError',
message: 'Value of "this" must be of type URLSearchParams'
});
}
// The URLSearchParams stringifier mutates the base URL using
// different percent-encoding rules than the URL itself.
{
const myUrl = new URL('https://example.org?foo=~bar');
assert.strictEqual(myUrl.search, '?foo=~bar');
myUrl.searchParams.sort();
assert.strictEqual(myUrl.search, '?foo=%7Ebar');
}