-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: errounous hash appended on url.format #1588
Comments
Yea ill fix this in a minute |
Is this a bug or is it how browsers behave? Shouldn't you be setting hash to null if you want no hash? |
So this is correct behaviour. |
Also I do not know how to remove the trailing "#" once it is there. |
I'm not seeing this. What are your steps? |
I see it too. |
This behavior seems to vary per browser. We can check the spec but given that we should maybe pick the most compatible choice for 2.0.0 (i.e. .hash = "" removes the hash) and for 3.0.0 either match the spec or get the spec changed. |
|
I think @domenic's suggestion to restore old behaviour is probably the way to go in that case, giving that the |
So far it seems that for So yeah I think we should restore the old behavior (definitely for empty string, possibly for null too?) and figure out the longer term story about spec/browser compliance in the future. With more testing of third-party packages this time :) |
@domenic the |
Old behavior seems good if I am reading the spec correctly: The hash attribute’s getter must run these steps:
The hash attribute’s setter must run these steps:
|
From the serializer part (used in href getter): If the exclude fragment flag is unset and url’s fragment is non-null, append "#" concatenated with url’s fragment to output. |
@targos that is not the spec, that is an outdated fork of the spec by another standards organization. Spec is at http://url.spec.whatwg.org/. But yes, the text has not been updated (much) in that section, so your quote is mostly right. |
The old behavior is incorrect with regard to |
@domenic ok thanks btw the > var uri = url.parse('http://www.example.com')
undefined
> uri.href
'http://www.example.com/'
> uri.hash = 'test'
'test'
> uri.href
'http://www.example.com/#test'
> uri.hash = null
null
> uri.href
'http://www.example.com/#test'
> uri.format()
'http://www.example.com/' Is this intended ? |
@targos probably not. > process.version
'v1.8.1'
> var uri = url.parse('http://www.example.com')
undefined
> uri.href
'http://www.example.com/'
> uri.hash = 'test'
'test'
> uri.href
'http://www.example.com/'
> uri.hash = null
null
> uri.href
'http://www.example.com/'
> uri.format()
'http://www.example.com/'
> uri.hash = 'test'
'test'
> uri.format()
'http://www.example.com/#test' |
yes href not always updating is a bug, i'll fix that as well |
ios.js: errounous hash appended on url.format nodejs/node#1588
In addition to null, undefined and the empty string are treated as empty (removing the component from the url). The string '#' is treated same as empty values when setting .hash. The string '?' is treated same as empty values when setting .search. Fixes nodejs#1588
PR-URL: #1589 Fixes: #1588 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
In addition to null, undefined and the empty string are treated as empty (removing the component from the url). The string '#' is treated same as empty values when setting .hash. The string '?' is treated same as empty values when setting .search. PR-URL: #1589 Fixes: #1588 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Fixed in 6687721 |
This is breaking npm installs and should be fixed before 2.0.0.
Encountered in https://github.com/npm/normalize-git-url/blob/master/normalize-git-url.js
1.8.1
2.0.0
cc: @petkaantonov @domenic @rvagg
The text was updated successfully, but these errors were encountered: