Skip to content

fix(ext/node): use primordials in ext/node/polyfills/internal/url.ts #29146

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 12 additions & 6 deletions ext/node/polyfills/internal/url.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
// Copyright 2018-2025 the Deno authors. MIT license.

// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials

import { fileURLToPath } from "node:url";
import { Buffer } from "node:buffer";
import { primordials } from "ext:core/mod.js";
const {
Number,
ObjectPrototypeIsPrototypeOf,
StringPrototypeSlice,
StringPrototypeStartsWith,
Symbol,
decodeURIComponent,
} = primordials;

const searchParams = Symbol("query");

export function toPathIfFileURL(
fileURLOrPath: string | Buffer | URL,
): string | Buffer {
if (!(fileURLOrPath instanceof URL)) {
if (!(ObjectPrototypeIsPrototypeOf(URL.prototype, fileURLOrPath))) {
return fileURLOrPath;
}
return fileURLToPath(fileURLOrPath);
Expand All @@ -26,8 +32,8 @@ export function urlToHttpOptions(url: any): any {
const options: any = {
protocol: url.protocol,
hostname: typeof url.hostname === "string" &&
url.hostname.startsWith("[")
? url.hostname.slice(1, -1)
StringPrototypeStartsWith(url.hostname, "[")
? StringPrototypeSlice(url.hostname, 1, -1)
: url.hostname,
hash: url.hash,
search: url.search,
Expand Down
Loading