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

url.format(undefined) fails in io.js, where it works in Node.js (TypeError: Cannot read property 'auth' of undefined) #1033

Closed
hairyhenderson opened this issue Mar 3, 2015 · 2 comments
Labels
confirmed-bug Issues with confirmed bugs. url Issues and PRs related to the legacy built-in url module.

Comments

@hairyhenderson
Copy link

In node.js (tested on v0.12.0 and v0.10.33):

$ node -e "console.log('%j',require('url').format(undefined))" 
""

In io.js (tested on v1.4.2 and v1.0.4):

$ node -e "console.log('%j',require('url').format(undefined))"
url.js:361
  var auth = this.auth || '';
                 ^
TypeError: Cannot read property 'auth' of undefined
    at Url.format (url.js:361:18)
    at Object.urlFormat [as format] (url.js:356:58)
    at [eval]:1:33
    at Object.exports.runInThisContext (vm.js:54:17)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:444:26)
    at evalScript (node.js:477:25)
    at startup (node.js:73:7)
    at node.js:863:3

I've dug into this a little bit, and I'm not really sure why it worked in node.js - probably something to do with different V8 versions? Even though this seems to be an edge case, this is a behaviour difference, and breaks a unit test in a project of mine.

@tellnes tellnes added confirmed-bug Issues with confirmed bugs. url Issues and PRs related to the legacy built-in url module. labels Mar 3, 2015
@tellnes
Copy link
Contributor

tellnes commented Mar 3, 2015

In #1036 we have decided to throw when passing invalid values to url.format. That means that this is working as intended except you should get another error message.

@hairyhenderson
Copy link
Author

Ok, I suppose that makes sense. I think when I hit this the undefined was being inserted by another module. Guess I'll track that down and log an issue for them ;)

Also, from the comments on #1036, it seems this is happening because of strict mode - makes more sense now. I was really confused why it ever worked in node!

tellnes added a commit to tellnes/io.js that referenced this issue Mar 4, 2015
`'use strict'` changes the behavior for `Function.prototype.call` when
the context is `undefined`. In earlier versions of node the value
`undefined` would make `url.format` look for fields in the global scope.

The docs states that `url.format` takes a parsed URL object and returns
a formatted URL string. So with this change it will now throw for other
values.

The exception is if the input is a string. Then it will call `url.parse`
on the string and then format it. The reason for that is that you can
call `url.format` on strings to clean up potentially wonky urls.

Fixes: nodejs#1033
PR-URL: nodejs#1036
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Julian Duque <[email protected]>
@tellnes tellnes closed this as completed Mar 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. url Issues and PRs related to the legacy built-in url module.
Projects
None yet
Development

No branches or pull requests

2 participants