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

Consider making URL's context symbol more private, or at least resetting the "flags" member #24211

Closed
domenic opened this issue Nov 6, 2018 · 7 comments
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Comments

@domenic
Copy link
Contributor

domenic commented Nov 6, 2018

  • Version: v10.8.0
  • Platform: Windows 10 64-bit
  • Subsystem: url

The (WHATWG) URL object's internal "context" symbol is exposed as an enumerable property on URL instances. This leads to it being considered for comparison by testing frameworks and the like.

For example, see https://repl.it/repls/StaidUnlinedFolder, wherein Jest considers new URL('./foo', 'https://example.com/') and new URL('https://example.com/foo') different because the former has flags: 496, and the latter has flags: 400.

The best solution would probably be using WeakMaps, or V8 private symbols. But you may be able to just make the url[context] property non-enumerable, and maybe that would placate Jest? Or even just reset url[context].flags after you're done parsing, so that even if your internals are exposed, you don't have this weird path-dependence.

/cc @nodejs/url

@devsnek devsnek added the whatwg-url Issues and PRs related to the WHATWG URL implementation. label Nov 7, 2018
@devsnek
Copy link
Member

devsnek commented Nov 7, 2018

sgtm, we already use WeakMap elsewhere in core for this.

@joyeecheung
Copy link
Member

Does IDL tests in WPT cover this? This is what I got from #24035 but I have not taken a closer look

[EXPECTED_FAILURE] URL interface: existence and properties of interface object
[EXPECTED_FAILURE] URL interface object length
[EXPECTED_FAILURE] URL interface: legacy window alias
[EXPECTED_FAILURE] URL interface: attribute href
[EXPECTED_FAILURE] URL interface: attribute origin
[EXPECTED_FAILURE] URL interface: attribute protocol
[EXPECTED_FAILURE] URL interface: attribute username
[EXPECTED_FAILURE] URL interface: attribute password
[EXPECTED_FAILURE] URL interface: attribute host
[EXPECTED_FAILURE] URL interface: attribute hostname
[EXPECTED_FAILURE] URL interface: attribute port
[EXPECTED_FAILURE] URL interface: attribute pathname
[EXPECTED_FAILURE] URL interface: attribute search
[EXPECTED_FAILURE] URL interface: attribute searchParams
[EXPECTED_FAILURE] URL interface: attribute hash
[EXPECTED_FAILURE] URLSearchParams interface: existence and properties of interface object

@joyeecheung
Copy link
Member

joyeecheung commented Nov 7, 2018

Minimal test case with our assert:

const assert = require('assert');

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

@joyeecheung
Copy link
Member

joyeecheung commented Nov 7, 2018

I looked into this a bit further - going hard-private in URL/URLSearchParams seems more complicated than I thought. For one, the symbol properties are displayed in util.inspect through showHidden, that is useful when debugging internals, it's still debuggable with WeakMap but that's less straightforward (though I guess you can also return the data store to the util.inspect.custom to bypass that). Also it requires a bit of refactoring to put them into WeakMap, so I am inclined to just make the context non-enumerable (as it should) first to fix Jest, and follow up with refactoring if anyone is interested in taking up the work..

Trott pushed a commit to Trott/io.js that referenced this issue Nov 9, 2018
At the moment we expose the context as a normal property on the
prototype chain of URL or take them from the base URL
which makes them enumerable and considered
by assert libraries even though the context carries path-dependent
information that do not affect the equivalence of these objects.
This patch fixes it in a minimal manner by marking the context
non-enumerable as making it full private would require more
refactoring and can be done in a bigger patch later.

PR-URL: nodejs#24218
Refs: nodejs#24211
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
BridgeAR pushed a commit that referenced this issue Nov 14, 2018
At the moment we expose the context as a normal property on the
prototype chain of URL or take them from the base URL
which makes them enumerable and considered
by assert libraries even though the context carries path-dependent
information that do not affect the equivalence of these objects.
This patch fixes it in a minimal manner by marking the context
non-enumerable as making it full private would require more
refactoring and can be done in a bigger patch later.

PR-URL: #24218
Refs: #24211
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
kiyomizumia pushed a commit to kiyomizumia/node that referenced this issue Nov 15, 2018
At the moment we expose the context as a normal property on the
prototype chain of URL or take them from the base URL
which makes them enumerable and considered
by assert libraries even though the context carries path-dependent
information that do not affect the equivalence of these objects.
This patch fixes it in a minimal manner by marking the context
non-enumerable as making it full private would require more
refactoring and can be done in a bigger patch later.

PR-URL: nodejs#24218
Refs: nodejs#24211
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
@Trott
Copy link
Member

Trott commented Nov 16, 2018

and follow up with refactoring if anyone is interested in taking up the work..

Adding a help wanted label based on that but feel free to remove it if you or someone else is already doing that.

@Trott Trott added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Nov 16, 2018
@joyeecheung
Copy link
Member

FTR I tried prototyping with WeakMaps but the performance regression was a bit uh....unacceptable (45
% ish compared to the 15% ish of using Object.defineProperty()). See #24218 (comment) for numbers.

It would still be nice to have a general refactoring in lib/internal/url.js but I guess that can be said about any file under lib/internal?

TimothyGu added a commit to TimothyGu/node that referenced this issue Nov 19, 2018
@TimothyGu TimothyGu mentioned this issue Nov 19, 2018
3 tasks
Trott pushed a commit to Trott/io.js that referenced this issue Dec 1, 2018
Fixes: nodejs#24211

PR-URL: nodejs#24495
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott
Copy link
Member

Trott commented Dec 1, 2018

Fixed in 639f641

@Trott Trott closed this as completed Dec 1, 2018
BridgeAR pushed a commit that referenced this issue Dec 5, 2018
Fixes: #24211

PR-URL: #24495
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
codebytere pushed a commit that referenced this issue Dec 14, 2018
At the moment we expose the context as a normal property on the
prototype chain of URL or take them from the base URL
which makes them enumerable and considered
by assert libraries even though the context carries path-dependent
information that do not affect the equivalence of these objects.
This patch fixes it in a minimal manner by marking the context
non-enumerable as making it full private would require more
refactoring and can be done in a bigger patch later.

PR-URL: #24218
Refs: #24211
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
MylesBorins pushed a commit that referenced this issue Dec 26, 2018
At the moment we expose the context as a normal property on the
prototype chain of URL or take them from the base URL
which makes them enumerable and considered
by assert libraries even though the context carries path-dependent
information that do not affect the equivalence of these objects.
This patch fixes it in a minimal manner by marking the context
non-enumerable as making it full private would require more
refactoring and can be done in a bigger patch later.

PR-URL: #24218
Refs: #24211
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
refack pushed a commit to refack/node that referenced this issue Jan 14, 2019
Fixes: nodejs#24211

PR-URL: nodejs#24495
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BethGriggs pushed a commit that referenced this issue Feb 12, 2019
Fixes: #24211

PR-URL: #24495
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
rvagg pushed a commit that referenced this issue Feb 28, 2019
Fixes: #24211

PR-URL: #24495
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants