( RaptoR | 2015. 10. 03., szo – 03:24 )

Röviden: miért akarna 2015-ben bárki is nem UTF-8-at használni?

Bővebben: Amikor megnyitja a latin2 fájlneves pdf-et, ezt a hibát dobja:


pdf.js:133 Uncaught (in promise) URIError: URI malformed
at decodeURIComponent (native)
at Object.PDFViewer (chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf.js:133:20)
at initViewer (chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/main.js:37:14)

Megnézve, hogy mi van a pdf.js-ben az említett helyen:


document.title = decodeURIComponent(getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl));

Ez pedig szabvány szerint:

The decodeURIComponent function computes a new version of a URI in which each escape sequence and UTF-8 encoding of the sort that might be introduced by the encodeURIComponent function is replaced with the UTF-16 encoding of the code points that it represents.

Magyarán azért nem működik Chrome-ban a dolog, mert be akarná állítani fájlnevet az lap címének, de mivel az nem UTF-8-ban van kódolva, ezért hibával leáll.

tl;dr: használj UTF-8-at.