Skip to content
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

test: add case for url.parse throwing a URIError #12135

Closed
wants to merge 1 commit into from

Conversation

lovell
Copy link
Contributor

@lovell lovell commented Mar 30, 2017

Hello, the url.parse function uses decodeURIComponent, which can throw a URIError, to parse the auth property of a URL. The example included here will test this path.

This PR also adds documentation on the possible errors that url.parse can throw. I'm happy to move this to a separate PR should this make things easier/cleaner.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

test, doc

@@ -16,3 +16,5 @@ const url = require('url');
].forEach(function(val) {
assert.throws(function() { url.parse(val); }, TypeError);
});

assert.throws(function() { url.parse('http://%E0%A4%A@fail'); }, URIError);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change the last parameter to assert.throws() to /^URIError: URI malformed$/.

The auth property of a URL is decoded via decodeURIComponent,
which can throw a URIError. The test URL here will trigger this.

Adds documentation on the possible errors url.parse can throw.
@mscdex mscdex added doc Issues and PRs related to the documentations. test Issues and PRs related to the tests. url Issues and PRs related to the legacy built-in url module. labels Mar 30, 2017
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

Still not sure if it's OK for Node.js to throw an URIError (because qsEscape is not a global URI handling function, even it is intended as a fast alternative for encodeURIComponent), but the test and the doc are definitely appreciated :)

@jasnell
Copy link
Member

jasnell commented Apr 4, 2017

jasnell pushed a commit that referenced this pull request Apr 4, 2017
The auth property of a URL is decoded via decodeURIComponent,
which can throw a URIError. The test URL here will trigger this.

Adds documentation on the possible errors url.parse can throw.

PR-URL: #12135
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell
Copy link
Member

jasnell commented Apr 4, 2017

Landed in 2ff107d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. test Issues and PRs related to the tests. url Issues and PRs related to the legacy built-in url module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants