uncaughtException when redirected to invalid URI #265

merged 1 commit into from Jun 7, 2012


None yet

2 participants

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://


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 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