Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const {
let urlParseWarned = false;

function urlParse(url, parseQueryString, slashesDenoteHost) {
if (!urlParseWarned && !isInsideNodeModules(2)) {
if (!urlParseWarned && !isInsideNodeModules(4)) {
urlParseWarned = true;
process.emitWarning(
'`url.parse()` behavior is not standardized and prone to ' +
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/node_modules/url-deprecations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions test/parallel/test-url-parse-deprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const common = require('../common');
const fixtures = require('../common/fixtures');

const assert = require('assert');
const url = require('url');

const fixturePath = fixtures.path('node_modules', 'url-deprecations.js');

// Application deprecation for url.parse()
url.parse('foo');
common.expectWarning('DeprecationWarning',
[/`url\.parse\(\)` behavior is not standardized/, 'DEP0169']);

// No warnings from inside node_modules
common.spawnPromisified(process.execPath, [fixturePath]).then(
common.mustCall(({ code, signal, stderr }) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.doesNotMatch(stderr, /\[DEP0169\]/);
})
);
Comment on lines +16 to +23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test result in affected versions:

AssertionError [ERR_ASSERTION]: The input was expected to not match the regular expression /\[DEP0169\]/. Input:

'(node:2065574) [DEP0169] DeprecationWarning: `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.\n' +
  '(Use `node --trace-deprecation ...` to show where the warning was created)\n'

    at /tmp/node/test/parallel/test-url-parse-deprecation.js:21:12
    at /tmp/node/test/common/index.js:507:15
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: '(node:2065574) [DEP0169] DeprecationWarning: `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.\n' +
    '(Use `node --trace-deprecation ...` to show where the warning was created)\n',
  expected: /\[DEP0169\]/,
  operator: 'doesNotMatch',
  diff: 'simple'
}

Node.js v24.14.0

7 changes: 0 additions & 7 deletions test/parallel/test-url-parse-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ if (common.hasIntl) {
}));
});

// Warning should only happen once per process.
common.expectWarning({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this expectation removed for direct url.parse() calls?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't, it's just moved into the consolidated deprecation test.

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.',
},
});
badURLs.forEach((badURL) => {
assert.throws(() => url.parse(badURL), {
code: 'ERR_INVALID_ARG_VALUE',
Expand Down
Loading