INDEX
A typical Firefox javascript error !
Symptoms
– the problem seems to occur only in Firefox (as of 02/2011)
– you will hardly notice it in Firefox’ debug window, however the Firebug extension show it clearly (see screenshot below)
Error message
An invalid or illegal string was specified » code: « 12
[Stopper sur une erreur] (99 out of range 41)
Context
– You are probably parsing XML, JSON, distant data
– You are probably using a javascript framework such as jQuery or Prototype
– You are probably trying to display, or store, part of the parsed data
The cause
Analyzing some data before they are parsed (in my case, it’s an XML feed of regions all across the globe), I’ve noticed some data were missing (see screenshot). To monitor my data, I’ve simply used console.log:
if (type_ville == types_villes) { locations.push(Array(nom, latlng[0], latlng[1], type_ville, nid)); console.log(Array(nom, latlng[0], latlng[1], type_ville, nid)); }
Kind of missing data in an XML context
I’ve noticed that data can be considered missing whether they are really blank, and also if they do not respect an established schema. In my case, I was trying to parse an array while the user input was missing the comma separator. (see code below).
Sample 1: wrong datatype
<node> <nom> <fr>Inta</fr> <en>Inta</en> <ru>Инта</ru> </nom> <marker_ville>66.0331421 60.1656114</marker_ville> <type_ville>Lieu de déportation</type_ville> <Nid>77</Nid> </node>
The field marker_ville should contain an array, but the comma is missing. Firefox is blocked the wrong datatype.
Sample 2: missing data
<node> <nom> <fr>Estonie</fr> </nom> <marker_ville></marker_ville> <type_ville>Lieu de résidence</type_ville> <Nid>281</Nid> </node>
Firefox won’t bypass this node even if marker_ville is empty. Chrome and other webkit-based browsers will, thought. Haven’t tested under IE.
Sample 3: missing data with shortened tag
<node> <nom> <fr>Kiev</fr> <en>Kiev</en> <ru>Киев</ru> </nom> <marker_ville/> <type_ville>Lieu de départ</type_ville> <Nid>70</Nid> </node>
I’ve tried this sample manually just to check. Even if marker_ville is empty and well-formed, Firefox won’t bypass it
Finally…
Having checked my data again, I couldn’t notice any undefined field (see screenshot below). After commented the console.log(), I was happy to see that my script was working again 🙂