Tuesday, 15 September 2015

encoding - Decode escaped cyrilic with javascript -



encoding - Decode escaped cyrilic with javascript -

the problem follows. because backend i'm working uses broken pylons 0.9.7 version, automatically escapes cookies on saving (i'm using pylons , having issues response.set_cookie . , can't update fixed rev) cyrilic url's saved in cookies request turn bizarre escaped strings. illustration :

ооо-фронталь.рф

will saved as

\320\276\320\276\320\276-\321\204\321\200\320\276\320\275\321\202\320\260\320\273\321\214.\321\200\321\204`

i've tried quoting urllib before save, i'm left :

'%5c320%5c276%5c320%5c276%5c320%5c276-%5c321%5c204%5c321%5c200%5c320%5c276%5c320%5c275%5c321%5c202%5c320%5c260%5c320%5c273%5c321%5c214.%5c321%5c200%5c321%5c204'

which doesn't create things improve in way. there way decode javascript ? encode/decodeuri dosen't work in case :/

they utf-8 octal escapes hard convert in javascript.

he way may work, although pretty terrible:

as hex \320\276 0xd0 0xbe url encoded %d0%be so:

var s = "\\320\\276\\320\\276\\320\\276-\\321\\204\\321\\200\\320\\276\\320\\275\\321\\202\\320\\260\\320\\273\\321\\214.\\321\\200\\321\\204" var r = s.replace(/\\(\d{3})?/g, function(a, b) { //octal hex homecoming "%" + parseint(b, 8).tostring(16); }); alert( decodeuricomponent(r) );

javascript encoding character-encoding decoding

No comments:

Post a Comment