Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: make the context non-enumerable #24218

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,14 @@ function onParseError(flags, input) {
// Reused by URL constructor and URL#href setter.
function parse(url, input, base) {
const base_context = base ? base[context] : undefined;
url[context] = new URLContext();
// In the URL#href setter
if (!url[context]) {
Object.defineProperty(url, context, {
enumerable: false,
configurable: false,
value: new URLContext()
});
}
_parse(input.trim(), -1, base_context, undefined,
onParseComplete.bind(url), onParseError);
}
Expand Down Expand Up @@ -1437,7 +1444,11 @@ function toPathIfFileURL(fileURLOrPath) {
}

function NativeURL(ctx) {
this[context] = ctx;
Object.defineProperty(this, context, {
enumerable: false,
configurable: false,
value: ctx
});
}
NativeURL.prototype = URL.prototype;

Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-whatwg-url-custom-no-enumerable-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
// This tests that the context of URL objects are not
// enumerable and thus considered by assert libraries.
// See https://github.com/nodejs/node/issues/24211

// Tests below are not from WPT.

require('../common');
const assert = require('assert');

assert.deepStrictEqual(
new URL('./foo', 'https://example.com/'),
new URL('https://example.com/foo')
);