Saturday, May 28, 2016

Javascript : Chrome console doesn't show difference between UTF-8 and UTF-16

Last night I spent about an hour trying to figure this bug out.  The problem was this :

- javascript downloads text file from server, file is full of urls

- js then compares document.URL (currently address the browser is at) to the text file (via storing the entries in a variable object then using indexOf).

so basically

if (current.URL exist in file) then {Do Stuff} else {return error}

Well I kept getting back errors and it made no sense.  So I got real basic and tried

if (current.URL == urlVariable) { return true }

Yet even this failed.  I forget why but I went into Firefox and in its console it is very clear the URL coming from the text file is very different than the URL string.  But in chrome they look the same.

Because the Chrome console doesn't properly indicate the text encoding is different I spent about an hour or so trying to "solve" why A does not equal A.  I thought I was taking crazy pills.

In short : Chrome console doesn't properly indicate when text encoding has changed.  And changes in character encoding can cause your "if equals" logic to fail in a confusing way.  If you're in FF console the issue will be obvious right away.

Array in Chrome



Array in Firefox


//]]>