Search code examples
angularjsurlunicodenon-ascii-characters

AngularJS non-ascii query parameter


I've run into a issue where a redirect to an AngularJS page can contain non-ascii characters as a query parameter.

When the query contains /?id=test%F6test the value instantly turns into /?id=undefined (by Angular I presume).

Is there a nice way around this?


Solution

  • The Unicode code point needs to encoded into UTF-8.

    For code point \u00F6, encode it as %C3%B6

    console.log(window.encodeURI("testötest"));
    console.log(window.encodeURI('\u00F6'));

    %F6 must never appear in a valid UTF-8 sequence.