Anchor Tag Doesn't Match EncodeURI/DecodURI
Reported by
alan....@optimizely.com,
Jan 24 2017
|
|||||||
Issue description
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
Steps to reproduce the problem:
1. create an anchor element `var anchor = document.createElement('a')`
2. set the href of the anchor `anchor.href = 'https://gamma`
3. get the origin of the anchor `anchor.origin === 'https://gamma`
What is the expected behavior?
I expect the return value of anchor.origin to be 'https://gamma.
What went wrong?
The returned string of anchor.origin is 'https://gamma%24', which is less than ideal, except that when I pass the string into decodeURI, decodeURI doesn't decode the '%24' into '. I kind of expect the return value of an anchor element to align with encodeURI/decodeURI.
I've checked in firefox and the returned value of anchor.origin is what I expected it to be.
Did this work before? N/A
Chrome version: 55.0.2883.95 Channel: stable
OS Version: OS X 10.11.6
Flash Version: Shockwave Flash 24.0 r0
,
Jan 24 2017
,
Jan 24 2017
@alan.sun: Thanks for filing the issue, could you please help us with a sample test case (an Html or a jsfiddle example). This will help us to triage the issue better. Thanks.!
,
Jan 24 2017
@ranjitkan, here's a jsfiddle: https://jsfiddle.net/2Lnk0qLd/1/
,
Jan 25 2017
Thanks for the fiddle example, launched the example on chrome version 55.0.2883.95 on MAC 10.12.2 and observed the output as attached in the screenshot in dev console. Same behavior is observed on M24 chrome version 24.0.1300.0. Is this issue you have mentioned about. Request you to please check and confirm
,
Jan 25 2017
The screenshot looks correct. The test cases I wrote out in the jsfiddle are, I think, the correct behavior.
,
Jan 25 2017
The dollar sign is an invalid character for a host name as per RFC spec [1] so decodeURI naturally should not decode %24 to $. You can use decodeURIComponent which will decode it.
In Chrome .href and .origin are calculated properties that return sanitized data. For example, international hostnames in Unicode will be returned in their actual http://xn--.... format. You can use .getAttribute('href') to get the original value.
In Firefox .href and .origin in this case return an invalid host name containing invalid characters. However decodeURI('http://foo%24') doesn't decode %24 as well, which is correct behavior.
It'd be nice if a knowledgeable chromium developer commented on whether there is a spec that regulates .href and .origin results.
[1]: https://tools.ietf.org/html/rfc952 - see the <name> rule.
,
Jan 25 2017
Thanks for the info. I just thought it was weird that '$' would get sanitized in the first place since encodeURI/decodeURI doesn't address it.
,
Jan 27 2017
,
Feb 22 2017
tyoshino, PTAL, this is a URL handling issue.
,
Mar 3 2017
I've confirmed that the behaviour is as described. I don't know what the correct behaviour is. Changing status to "Assigned".
,
Feb 26 2018
Reprioritization needed. |
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by alan....@optimizely.com
, Jan 24 2017