Skip to content

Commit

Permalink
refactor: completely remove url.parse() warning
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Jan 24, 2025
1 parent 4095aa9 commit a7ea7c7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
14 changes: 0 additions & 14 deletions src/js/node/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,11 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
"file:": true,
};

let urlParseWarned = false;
function urlParse(
url: string | URL | Url, // really has unknown type but intellisense is nice
parseQueryString?: boolean,
slashesDenoteHost?: boolean,
) {
const noDeprecation = process.noDeprecation;
const showDep = noDeprecation == null ? true : !noDeprecation;
if (!urlParseWarned && showDep && !lazyUtil().isInsideNodeModules()) {
urlParseWarned = true;
process.emitWarning(
"`url.parse()` behavior is not standardized and prone to " +
"errors that have security implications. Use the WHATWG URL API " +
"instead. CVEs are not issued for `url.parse()` vulnerabilities.",
"DeprecationWarning",
"DEP0169",
);
}

if ($isObject(url) && url instanceof Url) return url;

var u = new Url();
Expand Down
4 changes: 2 additions & 2 deletions test/js/node/test/parallel/test-url-parse-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ if (common.hasIntl) {
// Warning should only happen once per process.
common.expectWarning({
DeprecationWarning: {
// eslint-disable-next-line @stylistic/js/max-len
DEP0169: '`url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.',
// NOTE: this warning is noisy and annoying. We've disabled it intentionally.
// DEP0169: '`url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.',
DEP0170: `The URL ${badURLs[0]} is invalid. Future versions of Node.js will throw an error.`,
},
});
Expand Down
15 changes: 0 additions & 15 deletions test/js/node/url/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,3 @@ it("URL constructor throws ERR_MISSING_ARGS", () => {
// @ts-expect-error
expect(err?.code).toEqual("ERR_MISSING_ARGS");
});

describe("url.parse()", () => {
it("respects process.noDeprecation", () => {
const dir = tempDirWithFiles("url-parse", {
"index.js": `
process.noDeprecation = true;
const { parse } = require("url");
parse("http://example.com");
`,
});

const { stderr } = bunRun(path.join(dir, "index.js"));
expect(stderr).toBeEmpty();
});
});

0 comments on commit a7ea7c7

Please sign in to comment.