You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So this is correct behaviour. location.hash = null also removes the #. I think for a proper fix, we need to get an npm update, I'll open a PR on that repo.
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.
location.hash = null does transform it to #null in my browser (Firefox), but removes the hash completely (including '#') in both io.js 1.8.1 and 2.0.0.
So far it seems that for new URL objects, Chrome and Firefox have .hash = null giving #null and .hash = "" removing the hash. But for location, .hash = null gives #null and .hash = "" gives # (Chrome, Firefox, and IE). What a mess.
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 :)
@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 .hash = null, since hash is readonly attribute USVString (so any value, including null or undefined, gets converted to a string before processing). But we can fix that later, maybe.
Activity
petkaantonov commentedon May 2, 2015
Yea ill fix this in a minute
domenic commentedon May 2, 2015
Is this a bug or is it how browsers behave? Shouldn't you be setting hash to null if you want no hash?
targos commentedon May 2, 2015
On Chrome:
silverwind commentedon May 2, 2015
So this is correct behaviour.
location.hash = nullalso removes the#. I think for a proper fix, we need to get an npm update, I'll open a PR on that repo.targos commentedon May 2, 2015
Also I do not know how to remove the trailing "#" once it is there.
location.hash = nulltransforms it to "#null"silverwind commentedon May 2, 2015
I'm not seeing this. What are your steps?
Properly remove the hash part of the url
indutny commentedon May 2, 2015
I see it too.
domenic commentedon May 2, 2015
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.
silverwind commentedon May 2, 2015
location.hash = nulldoes transform it to#nullin my browser (Firefox), but removes the hash completely (including'#') in both io.js 1.8.1 and 2.0.0.silverwind commentedon May 2, 2015
I think @domenic's suggestion to restore old behaviour is probably the way to go in that case, giving that the
nullthing isn't conforming either.domenic commentedon May 2, 2015
So far it seems that for
new URLobjects, Chrome and Firefox have.hash = nullgiving#nulland.hash = ""removing the hash. But forlocation,.hash = nullgives#nulland.hash = ""gives#(Chrome, Firefox, and IE). What a mess.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 :)
1 remaining item
targos commentedon May 2, 2015
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:
targos commentedon May 2, 2015
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.
domenic commentedon May 2, 2015
@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.
domenic commentedon May 2, 2015
The old behavior is incorrect with regard to
.hash = null, sincehashisreadonly attribute USVString(so any value, including null or undefined, gets converted to a string before processing). But we can fix that later, maybe.targos commentedon May 2, 2015
@domenic ok thanks
btw the
hrefproperty is not always reset:Is this intended ?
silverwind commentedon May 2, 2015
@targos probably not.
.hrefwas never updated in the old implementation, by the way:petkaantonov commentedon May 2, 2015
yes href not always updating is a bug, i'll fix that as well
Avoid git-clone with an invalid URL
url: fix treatment of some values as non-empty
url: delete href cache on all setter code paths
url: fix treatment of some values as non-empty
petkaantonov commentedon May 3, 2015
Fixed in 6687721