Visitar URL original
URL polyfill: file: host and empty segments, blob: origin, and pathname = "" follow an old URL Standard · Issue #1586 · zloirock/core-js · GitHub
Skip to content

URL polyfill: file: host and empty segments, blob: origin, and pathname = "" follow an old URL Standard #1586

Closed

Description

@trackoor

The URL polyfill differs from current browsers, Node.js and WPT in three places that were changed in the URL Standard: file: URLs lose their host before a drive letter and lose leading empty path segments, blob: URLs with a non-http(s)/file inner URL get that URL's origin instead of "null", and setting pathname = "" on a path-only URL drops the /.

globalThis.URL = undefined;
require('core-js/actual/url');

console.log([
  new URL('file://h/C:/a/b').href,
  new URL('file://example.net/C:/').href,
  new URL('/', 'file://h/C:/a/b').href,
  new URL('C|', 'file://host/dir/file').href,
  new URL('file://spider///').href,
  new URL('file:////foo').href,
  new URL('file://localhost//a//../..//').href,
  new URL('blob:ftp://host/path').origin,
  new URL('blob:ws://example.org/').origin,
  (() => { const u = new URL('foo:/some/path'); u.pathname = ''; return u.href; })(),
]);

Actual (core-js 3.51.0):

[
  'file:///C:/a/b',
  'file:///C:/',
  'file:///C:/',
  'file:///C:',
  'file://spider/',
  'file:///foo',
  'file:///',
  'ftp://host',
  'ws://example.org',
  'foo:'
]

Expected (native URL in Node.js 26.13.0):

[
  'file://h/C:/a/b',
  'file://example.net/C:/',
  'file://h/C:/',
  'file://host/C:',
  'file://spider///',
  'file:////foo',
  'file://///',
  'null',
  'null',
  'foo:/'
]

Spec: https://url.spec.whatwg.org/#path-state (no host clearing for a drive letter, no stripping of leading empty segments), the blob case of https://url.spec.whatwg.org/#concept-url-origin (only http, https and file inner URLs), and the state-override step of https://url.spec.whatwg.org/#path-start-state.

In modules/web.url.constructor.js (same on master fd36b6f) these are if (url.host !== null && url.host !== '') url.host = ''; and the while (url.path.length > 1 && url.path[0] === '') shift(url.path); loop in case PATH, getOrigin for blob without the scheme check, and the missing "append an empty segment when there is a state override and the host is null" at the end of case PATH_START.

Credit: https://ucsbplse.github.io/

Activity

  1. added a commit that references this issue on Nov 11, 2026
    e2b15cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions