querystring: convert to using internal/errors
PR-URL: https://github.com/nodejs/node/pull/15565 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
parent
1c0772444c
commit
9788e96836
@ -1116,6 +1116,11 @@ API] [`URLSearchParams` constructor][`new URLSearchParams(iterable)`] does not
|
|||||||
represent a `[name, value]` tuple – that is, if an element is not iterable, or
|
represent a `[name, value]` tuple – that is, if an element is not iterable, or
|
||||||
does not consist of exactly two elements.
|
does not consist of exactly two elements.
|
||||||
|
|
||||||
|
<a id="ERR_INVALID_URI"></a>
|
||||||
|
### ERR_INVALID_URI
|
||||||
|
|
||||||
|
Used when an invalid URI is passed.
|
||||||
|
|
||||||
<a id="ERR_INVALID_URL"></a>
|
<a id="ERR_INVALID_URL"></a>
|
||||||
### ERR_INVALID_URL
|
### ERR_INVALID_URL
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ module.exports = exports = {
|
|||||||
Error: makeNodeError(Error),
|
Error: makeNodeError(Error),
|
||||||
TypeError: makeNodeError(TypeError),
|
TypeError: makeNodeError(TypeError),
|
||||||
RangeError: makeNodeError(RangeError),
|
RangeError: makeNodeError(RangeError),
|
||||||
|
URIError: makeNodeError(URIError),
|
||||||
AssertionError,
|
AssertionError,
|
||||||
E // This is exported only to facilitate testing.
|
E // This is exported only to facilitate testing.
|
||||||
};
|
};
|
||||||
@ -287,6 +288,7 @@ E('ERR_INVALID_SYNC_FORK_INPUT',
|
|||||||
'Asynchronous forks do not support Buffer, Uint8Array or string input: %s');
|
'Asynchronous forks do not support Buffer, Uint8Array or string input: %s');
|
||||||
E('ERR_INVALID_THIS', 'Value of "this" must be of type %s');
|
E('ERR_INVALID_THIS', 'Value of "this" must be of type %s');
|
||||||
E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
|
E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
|
||||||
|
E('ERR_INVALID_URI', 'URI malformed');
|
||||||
E('ERR_INVALID_URL', 'Invalid URL: %s');
|
E('ERR_INVALID_URL', 'Invalid URL: %s');
|
||||||
E('ERR_INVALID_URL_SCHEME',
|
E('ERR_INVALID_URL_SCHEME',
|
||||||
(expected) => `The URL must be ${oneOf(expected, 'scheme')}`);
|
(expected) => `The URL must be ${oneOf(expected, 'scheme')}`);
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
|
const errors = require('internal/errors');
|
||||||
const {
|
const {
|
||||||
hexTable,
|
hexTable,
|
||||||
isHexTable
|
isHexTable
|
||||||
@ -174,11 +175,12 @@ function qsEscape(str) {
|
|||||||
}
|
}
|
||||||
// Surrogate pair
|
// Surrogate pair
|
||||||
++i;
|
++i;
|
||||||
var c2;
|
|
||||||
if (i < str.length)
|
if (i >= str.length)
|
||||||
c2 = str.charCodeAt(i) & 0x3FF;
|
throw new errors.URIError('ERR_INVALID_URI');
|
||||||
else
|
|
||||||
throw new URIError('URI malformed');
|
var c2 = str.charCodeAt(i) & 0x3FF;
|
||||||
|
|
||||||
lastPos = i + 1;
|
lastPos = i + 1;
|
||||||
c = 0x10000 + (((c & 0x3FF) << 10) | c2);
|
c = 0x10000 + (((c & 0x3FF) << 10) | c2);
|
||||||
out += hexTable[0xF0 | (c >> 18)] +
|
out += hexTable[0xF0 | (c >> 18)] +
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const qs = require('querystring');
|
const qs = require('querystring');
|
||||||
@ -12,8 +12,15 @@ assert.deepStrictEqual(qs.escape('Ŋōđĕ'), '%C5%8A%C5%8D%C4%91%C4%95');
|
|||||||
assert.deepStrictEqual(qs.escape('testŊōđĕ'), 'test%C5%8A%C5%8D%C4%91%C4%95');
|
assert.deepStrictEqual(qs.escape('testŊōđĕ'), 'test%C5%8A%C5%8D%C4%91%C4%95');
|
||||||
assert.deepStrictEqual(qs.escape(`${String.fromCharCode(0xD800 + 1)}test`),
|
assert.deepStrictEqual(qs.escape(`${String.fromCharCode(0xD800 + 1)}test`),
|
||||||
'%F0%90%91%B4est');
|
'%F0%90%91%B4est');
|
||||||
assert.throws(() => qs.escape(String.fromCharCode(0xD800 + 1)),
|
|
||||||
/^URIError: URI malformed$/);
|
common.expectsError(
|
||||||
|
() => qs.escape(String.fromCharCode(0xD800 + 1)),
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_URI',
|
||||||
|
type: URIError,
|
||||||
|
message: 'URI malformed'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// using toString for objects
|
// using toString for objects
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const inspect = require('util').inspect;
|
const inspect = require('util').inspect;
|
||||||
|
|
||||||
@ -271,9 +271,14 @@ qsWeirdObjects.forEach(function(testCase) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// invalid surrogate pair throws URIError
|
// invalid surrogate pair throws URIError
|
||||||
assert.throws(function() {
|
common.expectsError(
|
||||||
qs.stringify({ foo: '\udc00' });
|
() => qs.stringify({ foo: '\udc00' }),
|
||||||
}, /^URIError: URI malformed$/);
|
{
|
||||||
|
code: 'ERR_INVALID_URI',
|
||||||
|
type: URIError,
|
||||||
|
message: 'URI malformed'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// coerce numbers to string
|
// coerce numbers to string
|
||||||
assert.strictEqual('foo=0', qs.stringify({ foo: 0 }));
|
assert.strictEqual('foo=0', qs.stringify({ foo: 0 }));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user