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

Invalid URI throws exception when NO_PROXY is set in environment #1595

Closed
catharinejm opened this issue May 21, 2015 · 2 comments · Fixed by #1599
Closed

Invalid URI throws exception when NO_PROXY is set in environment #1595

catharinejm opened this issue May 21, 2015 · 2 comments · Fixed by #1599

Comments

@catharinejm
Copy link

> request.post({uri: 'invalid'}, function(err, res){ })
/.../node_modules/request/lib/getProxyFromURI.js:5
  return hostname.replace(/^\.*/, '.').toLowerCase()
                 ^
TypeError: Cannot read property 'replace' of null
  at formatHostname (/.../node_modules/request/lib/getProxyFromURI.js:5:18)
  at uriInNoProxy (/.../node_modules/request/lib/getProxyFromURI.js:21:18)
  at getProxyFromURI (/.../node_modules/request/lib/getProxyFromURI.js:55:25)
  at Request.init (/.../node_modules/request/request.js:447:18)

The URI validation happens on line 457 of request.js, but when NO_PROXY is set in the environment, the hostname is parsed out of the URI before the validation happens. If an invalid URI has no hostname, then the above null error is thrown, which is no good for asynchronous code.

It looks like it'd be possible to move the URI validation above the proxy and tunnel bits, so that the error can be emitted normally.

@simov
Copy link
Member

simov commented May 25, 2015

Good call @jondistad fixed in #1599

@catharinejm
Copy link
Author

Excellent, thanks!

simov added a commit that referenced this issue May 26, 2015
Move getProxyFromURI logic below the check for Invaild URI (#1595)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants