Skip to content

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

Closed
@domenic

Description

@domenic
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.whatwg-urlIssues and PRs related to the WHATWG URL implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions