Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function urlRewriteProxyRequest (req, res, next) {
var proxiedUrlPartRegExp = /^\/\S+?\/(https?:)/;
if (proxiedUrlPartRegExp.test(req.url) && req.url.indexOf(unchangeableUrlSession) === -1) {
// NOTE: Store the destination URL so we can send it back for testing purposes (see GET xhr-test route).
req.originalUrl = req.url;
var url = req.url.replace(proxiedUrlPartRegExp, '$1');
// NOTE: Create host-relative URL.
var parsedUrl = urlParser.parse(url);
parsedUrl.host = null;
parsedUrl.hostname = null;
parsedUrl.port = null;
parsedUrl.protocol = null;
parsedUrl.slashes = false;
req.url = urlParser.format(parsedUrl);
}
next();
}
test(function() {
var seed = new URLSearchParams('a=b&c=d');
var params = new URLSearchParams(seed);
assert_true(params != null, 'constructor returned non-null value.');
assert_equals(params.get('a'), 'b');
assert_equals(params.get('c'), 'd');
assert_false(params.has('d'));
// The name-value pairs are copied when created; later updates
// should not be observable.
seed.append('e', 'f');
assert_false(params.has('e'));
params.append('g', 'h');
assert_false(seed.has('g'));
}, 'URLSearchParams constructor, object.');
test(function() {
var params = new URLSearchParams();
params.append('first', 1);
params.append('second', 2);
params.append('third', '');
params.append('first', 10);
assert_true(params.has('first'), 'Search params object has name "first"');
assert_equals(params.get('first'), '1', 'Search params object has name "first" with value "1"');
assert_equals(params.get('second'), '2', 'Search params object has name "second" with value "2"');
assert_equals(params.get('third'), '', 'Search params object has name "third" with value ""');
params.append('first', 10);
assert_equals(params.get('first'), '1', 'Search params object has name "first" with value "1"');
}, 'Append multiple');
/* eslint-enable */
const parentURL = pathToFileURL(parentFilepath);
const parentBody = 'require(\'./dep.js\')';
const workerSpawningFilepath = path.join(tmpdir.path, 'worker_spawner.js');
const workerSpawningURL = pathToFileURL(workerSpawningFilepath);
const workerSpawningBody = `
const { Worker } = require('worker_threads');
// make sure this is gone to ensure we don't do another fs read of it
// will error out if we do
require('fs').unlinkSync(${JSON.stringify(policyFilepath)});
const w = new Worker(${JSON.stringify(parentFilepath)});
w.on('exit', process.exit);
`;
const depFilepath = path.join(tmpdir.path, 'dep.js');
const depURL = pathToFileURL(depFilepath);
const depBody = '';
const policyToDepRelativeURLString = `./${
path.relative(path.dirname(policyFilepath), depFilepath)
}`;
fs.writeFileSync(parentFilepath, parentBody);
fs.writeFileSync(depFilepath, depBody);
const tmpdirURL = pathToFileURL(tmpdir.path);
if (!tmpdirURL.pathname.endsWith('/')) {
tmpdirURL.pathname += '/';
}
function test({
shouldFail = false,
preload = [],
entry,
assert.deepEqual(values.next(), { value: "123", done: false});
assert.deepEqual(values.next(), { value: "xyz", done: false});
assert.deepEqual(values.next(), { value: undefined, done: true});
searchParams.set('abc', 'b');
assert.deepEqual(searchParams.getAll('abc'), ['b']);
searchParams.delete('a');
assert(!searchParams.has('a'));
assert.equal(searchParams.get('a'), null);
searchParams.sort();
}
{
const searchParams = new url.URLSearchParams({
user: 'abc',
query: ['first', 'second']
});
assert.equal(searchParams.toString(), 'user=abc&query=first%2Csecond');
assert.deepEqual(searchParams.getAll('query'), ['first,second']);
}
{
// Using an array
let params = new url.URLSearchParams([
['user', 'abc'],
['query', 'first'],
['query', 'second']
]);
assert.equal(params.toString(), 'user=abc&query=first&query=second');
const fileURL = url.pathToFileURL('test/').href;
assert.ok(fileURL.startsWith('file:///'));
assert.ok(fileURL.endsWith('/'));
}
{
const fileURL = url.pathToFileURL('test\\').href;
assert.ok(fileURL.startsWith('file:///'));
if (isWindows)
assert.ok(fileURL.endsWith('/'));
else
assert.ok(fileURL.endsWith('%5C'));
}
{
const fileURL = url.pathToFileURL('test/%').href;
assert.ok(fileURL.includes('%25'));
}
{
let testCases;
if (isWindows) {
testCases = [
// lowercase ascii alpha
{ path: 'C:\\foo', expected: 'file:///C:/foo' },
// uppercase ascii alpha
{ path: 'C:\\FOO', expected: 'file:///C:/FOO' },
// dir
{ path: 'C:\\dir\\foo', expected: 'file:///C:/dir/foo' },
// trailing separator
{ path: 'C:\\dir\\', expected: 'file:///C:/dir/' },
// dot
);
{
const expectedError = common.expectsError(
{ code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
assert.throws(() => domainToASCII(), expectedError);
assert.throws(() => domainToUnicode(), expectedError);
assert.strictEqual(domainToASCII(undefined), 'undefined');
assert.strictEqual(domainToUnicode(undefined), 'undefined');
}
{
for (const [i, { ascii, unicode }] of tests.entries()) {
assert.strictEqual(ascii, domainToASCII(unicode),
`domainToASCII(${i + 1})`);
assert.strictEqual(unicode, domainToUnicode(ascii),
`domainToUnicode(${i + 1})`);
assert.strictEqual(ascii, domainToASCII(domainToUnicode(ascii)),
`domainToASCII(domainToUnicode(${i + 1}))`);
assert.strictEqual(unicode, domainToUnicode(domainToASCII(unicode)),
`domainToUnicode(domainToASCII(${i + 1}))`);
}
}
{
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
{ code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
assert.throws(() => domainToASCII(), expectedError);
assert.throws(() => domainToUnicode(), expectedError);
assert.strictEqual(domainToASCII(undefined), 'undefined');
assert.strictEqual(domainToUnicode(undefined), 'undefined');
}
{
for (const [i, { ascii, unicode }] of tests.entries()) {
assert.strictEqual(ascii, domainToASCII(unicode),
`domainToASCII(${i + 1})`);
assert.strictEqual(unicode, domainToUnicode(ascii),
`domainToUnicode(${i + 1})`);
assert.strictEqual(ascii, domainToASCII(domainToUnicode(ascii)),
`domainToASCII(domainToUnicode(${i + 1}))`);
assert.strictEqual(unicode, domainToUnicode(domainToASCII(unicode)),
`domainToUnicode(domainToASCII(${i + 1}))`);
}
}
{
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);
assert.strictEqual(domainToUnicode(input), '', caseComment);
} else {
}
{
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);
assert.strictEqual(domainToUnicode(input), '', caseComment);
} else {
assert.strictEqual(domainToASCII(input), output, caseComment);
const roundtripped = domainToASCII(domainToUnicode(input));
assert.strictEqual(roundtripped, output, caseComment);
}
}
}
{
const expectedError = common.expectsError(
{ code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
assert.throws(() => domainToASCII(), expectedError);
assert.throws(() => domainToUnicode(), expectedError);
assert.strictEqual(domainToASCII(undefined), 'undefined');
assert.strictEqual(domainToUnicode(undefined), 'undefined');
}
{
for (const [i, { ascii, unicode }] of tests.entries()) {
assert.strictEqual(ascii, domainToASCII(unicode),
`domainToASCII(${i + 1})`);
assert.strictEqual(unicode, domainToUnicode(ascii),
`domainToUnicode(${i + 1})`);
assert.strictEqual(ascii, domainToASCII(domainToUnicode(ascii)),
`domainToASCII(domainToUnicode(${i + 1}))`);
assert.strictEqual(unicode, domainToUnicode(domainToASCII(unicode)),
`domainToUnicode(domainToASCII(${i + 1}))`);
}
}
{
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);