javascript - Handling a windows-1250 URI in node.js/express -
my app depends on webservice form it's uris, comes (what believe is) windows-1250 encoded string (/punk%92d
) , express fails follows:
connect 400 error: failed decode param 'punk%92d' @ layer.match
so thought converting each link segment utf-8 (example: /punk’d
, there no reference offending enconding), , 1 time again windows-1250 work external webservice.
i tried approach using both iconv
, iconv-lite
there's wrong results: /punk d
, /punk�d
, etc.
here's sample using iconv:
var str = 'punk’d'; var buf = new buffer(str.tostring('binary'), 'binary'); console.log(new iconv('utf-8', 'windows-1250').convert(buf).tostring('binary'));
…and iconv-lite:
console.log(iconv.decode(new buffer(str), 'win1250'));
i know using binary
bad approach, hoping something, anything job. tried multiple variations of code since knowledge of buffers
limited, simpler things wouldn't work, like:
console.log(new buffer('punk’d').tostring('utf-8'));
so i'm interested in either way handle encoded strings in uri within express, or effective way convert them within node.js.
sorry if seems simple of thing try, since node , express both javascript, have tried using decodeuricomponent('punk’d')
? looks me it's standard encoded uri. think you're getting weird output iconv because you're converting wrong encoding.
javascript node.js express encoding iconv
No comments:
Post a Comment