Closed Bug 1322965 Opened 7 years ago Closed 7 years ago

Documentation says encodeURIComponent encodes charater & - it doesn't

Categories

(Firefox :: Untriaged, defect)

50 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: birger, Unassigned, NeedInfo)

References

()

Details

:: Developer Documentation Request

      Request Type: Correction
     Gecko Version: Trunk
 Technical Contact: 

:: Details

Have no idea what version of gecko, nor where to get it.
Seems this is always the problem with reporting bug til Mozilla. It is more work to report it, than to find a way around the bug.

Not really sure, what details you want.
The js function encodeURIComponent() does NOT encode the &-character as documentation says it does.
Try it...
Could you post the result of the following instruction on your console:
console.log(encodeURIComponent("&"));
?

Using the different channels of Firefox (nightly/dev edition/release), when up to date, I get the following result printed in the console : %26 (the encoded value for "&").

If necessary, could you provide a snippet of code for which you think the function is erroneous? (stating  it doesn't help solve the problem).
Flags: needinfo?(birger)
I get that too.
and when ask it to encodeURIComponent('you & me'), I get 'you & me' ...

encodeURIComponent(('you & me').replace(/&/g, '%27'))
How do you check the result?
can you post the standalone testcase that you used to see the result?
Also, on which version on which OS are you testing?
WIN7 Home Premium 64bit, FF 50.02
8GB Ram

Used with AJAX - calling parameters are garbeled, when attempting to use encodeURIComponent to escape them correct, and one of them contains an &

Network section of the build-in development tool, shows them to be wrong in request parameters - & is not escaped. (text following the & is taken as name for a parameter - not as part of the value of the previous parameter, as it should if encodeURIComponent was doing it's job)
(Build in tool has its own problems - as for instanse showing & when the code actually says & and a couple of other pecularities, errrormessages that are not about errors, but developers trying to meddel in other peoples work - so in essense that might be part of the cause of the trouble; but the workaround gets the job done, anyhow.)

And no - I do not have the time to create a standalone.
Just noted the misbehaving, and thought you migh want to know...
there's nothing we can do for your case without any testcase.
it's hard to say which part is wrong, but most likely other part, or perhaps your code contains modified version of encodeURIComponent.

if the page is publicly available online, can you post the URL?
Component: JavaScript → Untriaged
OS: Other → Windows 7
Priority: P5 → --
Product: Developer Documentation → Firefox
Hardware: All → x86_64
Version: unspecified → 50 Branch
I have made no modifications to built-in functionality, and is not using other tools than my own assemblys of functions written in pure javascript.
Page is not publically available yet and will not become public (will require password) - and workaround is in effect anyway.
http://jsbin.com/tadetatiwo/edit?html,output

Please see this test case and tell me if it's ok.

I tested on Windows 7 x32 and Mac OS X 10.10 with FF 50 release and FF Nightly 53.0a1 and using the above test case the &-character is encoded.
Looks fine.
Tried removing my workaround, and still get the problem...

I'm on Win7 x64, and the result takes a trip through AJAX - XMLHttpRequest Object -, before being presented to PHP as parameters on adress line. And there they are NOT interpreted correct.

Network section of FF's build in tool, even reports it as an ekstra parameter....
Beats me...
can you put the following code into your website and check what's logged to web console?

  console.log(encodeURIComponent('you & me'));

if "you%20%26%20me" is logged, encodeURIComponent is working properly and something else is breaking the output.
if "you & me" is logged, your code contains modified encodeURIComponent.
Where do I see it?
Put it in wondows onload event handler.

Only thing in consol is the idiotic repeating af the error - that is not an error, but developers harassing other deelopers...
"Brug af synkron XMLHttpRequest i hovedtråden er forældet på grund af dens skadelige effekt på brugeroplevelsen. Læs mere på http://xhr.spec.whatwg.org/"
Did (smething like) this instead :
document.getElementById('someElement').innerHTML = encodeURIComponent('you & me')

and the element then displays : you%20%26%20me

So aparantly it's something else, not workting together as it should....
So your output from "you & me" is "you%20%26%20me" right?
Hi,
Marking this as Resolved: Incomplete due to the lack of response from  Birger Sørensen.
Birger feel free to reopen this if you still have the same issue, and also please add some more info that can help us fixing this.
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.