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

.equals(undefined) #189

Closed
yuhama opened this Issue Feb 24, 2015 · 5 comments

Comments

Projects
None yet
2 participants
@yuhama
Contributor

yuhama commented Feb 24, 2015

If I am on the page "http://local.local" and run URI('http://local.local').equals(undefined) I get true. Comparing a different URL to undefined gives false. As far as I can tell, this only happens if the argument to URI is the current page URL.

I assume this is so that URI() is a shortcut for current URL. This can be differentiated by looking at arguments. Will make a pull request.

Using version 1.14.1.

@rodneyrehm

This comment has been minimized.

Show comment
Hide comment
@rodneyrehm

rodneyrehm Feb 24, 2015

Member

that's because .equal() runs the argument through URI(), making the following all do the same thing:

URI(location.href).equals(URI(location.href)) === true;
URI(location.href).equals(URI()) === true;
URI(location.href).equals() === true;

URI().equals(URI(location.href)) === true;
URI().equals(URI()) === true;
URI().equals() === true;

I don't consider this a bug. Maybe the documentation could be more clear about it…

Member

rodneyrehm commented Feb 24, 2015

that's because .equal() runs the argument through URI(), making the following all do the same thing:

URI(location.href).equals(URI(location.href)) === true;
URI(location.href).equals(URI()) === true;
URI(location.href).equals() === true;

URI().equals(URI(location.href)) === true;
URI().equals(URI()) === true;
URI().equals() === true;

I don't consider this a bug. Maybe the documentation could be more clear about it…

@yuhama

This comment has been minimized.

Show comment
Hide comment
@yuhama

yuhama Feb 24, 2015

Contributor

While all of those make sense

URI(undefined).equals(URI()) === true

doesn't really. It is very easy to make mistakes by inputting something you think is a value (but is really undefined) to URI. This is not a logical behavior. A possible solution would be adding

if (arguments.length === 1) {
  throw new TypeError('undefined is not a valid argument for URI');
}

to line 43. But obviously it is your call!

Contributor

yuhama commented Feb 24, 2015

While all of those make sense

URI(undefined).equals(URI()) === true

doesn't really. It is very easy to make mistakes by inputting something you think is a value (but is really undefined) to URI. This is not a logical behavior. A possible solution would be adding

if (arguments.length === 1) {
  throw new TypeError('undefined is not a valid argument for URI');
}

to line 43. But obviously it is your call!

@rodneyrehm

This comment has been minimized.

Show comment
Hide comment
@rodneyrehm

rodneyrehm Feb 24, 2015

Member

(I took the liberty of fixing your code examples and make line 43 be 100x more useful by linking it to the mentioned line…)

The constructor takes 2 arguments, so you'd likely check if (arguments.length) instead, agree?
PR welcome, don't forget the tests :)

But obviously it is your call!

Actually it's the community's, as your suggested change introduces a (tiny) backward compatibility break (which I assume most people wouldn't run into):

// currently equivalent
URI(undefined);
URI(location.href);

But I guess that's fine, considering that you suggested throwing an error instead of silently using the empty string.

Member

rodneyrehm commented Feb 24, 2015

(I took the liberty of fixing your code examples and make line 43 be 100x more useful by linking it to the mentioned line…)

The constructor takes 2 arguments, so you'd likely check if (arguments.length) instead, agree?
PR welcome, don't forget the tests :)

But obviously it is your call!

Actually it's the community's, as your suggested change introduces a (tiny) backward compatibility break (which I assume most people wouldn't run into):

// currently equivalent
URI(undefined);
URI(location.href);

But I guess that's fine, considering that you suggested throwing an error instead of silently using the empty string.

@rodneyrehm

This comment has been minimized.

Show comment
Hide comment
@rodneyrehm

rodneyrehm Mar 11, 2015

Member

@eakron do you want to send a PR to fix this issue?

Member

rodneyrehm commented Mar 11, 2015

@eakron do you want to send a PR to fix this issue?

@rodneyrehm rodneyrehm added the Bug label Mar 11, 2015

@yuhama

This comment has been minimized.

Show comment
Hide comment
@yuhama

yuhama Mar 11, 2015

Contributor

Pull request: #196

Contributor

yuhama commented Mar 11, 2015

Pull request: #196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment