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

uncaughtException when redirected to invalid URI #265

Merged
merged 1 commit into from
Jun 7, 2012

Conversation

naholyr
Copy link
Contributor

@naholyr naholyr commented Jun 7, 2012

We recently faced a case of uncaught exception: when a website redirects (using Location header) to a syntactically invalid URI, we end up with an ugly Uncaught Exception TypeError: Cannot call method 'indexOf' of undefined.

Here is the stack trace:

TypeError: Cannot call method 'indexOf' of undefined
    at /…/node_modules/request/vendor/cookie/jar.js:51:19
    at Array.filter (native)
    at CookieJar.get (/…/node_modules/request/vendor/cookie/jar.js:50:23)
    at Request.request (/…/node_modules/request/main.js:156:29)
    at request (/…/node_modules/request/main.js:570:5)
    at ClientRequest.<anonymous> (/…/node_modules/request/main.js:385:9)
    at ClientRequest.g (events.js:156:14)
    at ClientRequest.emit (events.js:67:17)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1256:7)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:91:29)

And the real-life case:

$ curl -i 'http://indicecorporativo.com/component/flexbanner/?task=click&bannerid=1'
…
Location: http://
…

Boom.

This PR will check the URI before going further, and if it's invalid it will emit an "error" event, which will make it catchable.

mikeal added a commit that referenced this pull request Jun 7, 2012
uncaughtException when redirected to invalid URI
@mikeal mikeal merged commit 5f1133a into request:master Jun 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

None yet

2 participants