locutusjs / locutus

Bringing stdlibs of other programming languages to JavaScript for educational purposes

Home Page:https://locutus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swedish characters åäö not replaced correctly with urlencode()

Snorvarg opened this issue · comments

Hi,
I am using your urlencode-function, but found it did not handle Swedish characters åäö correctly.

My workaround was simple:

  // åäö is not replaced correctly. 'å' for example, encodeURIComponent() produce "%C3%A5", while php's urldecode() expects "%25C3%25A5".
  str = str.replace(/å/g, "%25C3%25A5");
  str = str.replace(/ä/g, "%25C3%25A4");
  str = str.replace(/ö/g, "%25C3%25B6");

http://locutus.io/php/url/urlencode/

"%C3%A5" for "å" is correct. "%25C3%25A5" would be double-encoded ("%25" is the sequence for the percentage sign "%"). Were you calling urldecode twice or something?

Interesting thought! It was many years ago and I had a database with things other people had been working with, so it is probably as you say, I was decoding twice.