You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Can you give me an example of just running decodeURIComponent where it's not doing what you expect?

    With your example I get:

    // Espruino
    >decodeURIComponent("PLUS%2B%2B%2B%2BLEE­R+++++OK")
    ="PLUS++++LEER+++++OK"
    // Chrome
    >decodeURIComponent("PLUS%2B%2B%2B%2BLEE­R+++++OK")
    ="PLUS++++LEER+++++OK"
    // Node.js
    > decodeURIComponent("PLUS%2B%2B%2B%2BLEER­+++++OK")
    ='PLUS++++LEER+++++OK'
    

    So I'd say it's behaving as expected.

    However it's not desperately helpful for what you're trying to do. You could try decodeURIComponent(els[1].replace(/+/g,"­ "));

    Looking online it seems that is the accepted way of doing it: https://stackoverflow.com/a/24417399/121­5872

  • However it's not desperately helpful for what you're trying to do. You could try decodeURIComponent(els[1].replace(/+/g,"­ "));

    That is exactly what I do to fix it but I thought that decodeURIComponent should already result the same.
    It seems that it is my fault. Why are spaces something so special?

    application/x-www-form-urlencoded Default. All characters are encoded before sent (spaces are converted to "+" symbols, and special characters are converted to ASCII HEX values)
    https://www.w3schools.com/tags/att_form_­enctype.asp

    I expected that a space would be

     U+0020		 	Space
    

    not just an "+".

    Confusing for me :)

    Thank you for your help!

    PS: Espruino is very cool :)

About

Avatar for Gordon @Gordon started