Bug under at least IE 8 and a potential fix
Closed this issue · 1 comments
The problem is in _decode:
for (var prop in obj) {
if (!Array.isArray(obj)) {
if (obj.hasOwnProperty(prop)) {
obj[_keys[prop]] = _decode(obj[prop]);
delete obj[prop];
}
} else {
obj[prop] = _decode(obj[prop]);
}
}
The code iterates over the properties of obj, which it expects to generally have keys which are strings representing a numeric index into _keys, and values which need to be decoded. It deletes these and adds properties with the name from _keys and the decoded value from a recursive call to _decode. In Chrome these newly added properties are not iterated over, but in Internet Explorer 8 (and perhaps others) they are. The proposed fix is to not do anything if the property is not in _keys. This seems to work for at least the case that was breaking me.
for (var prop in obj) { // IE 8 seems like it might do things in funny order when stuff is deleted? http://stackoverflow.com/questions/3122548/iterating-javascript-object-properties-and-arrays-with-for-in-when-ordering-is
if (!Array.isArray(obj)) {
if (obj.hasOwnProperty(prop)) { // In case iteration follows inheritance chain? In case it has been deleted?
if (_keys[prop]) { // For IE 8 and perhaps other browsers which iterate over the props we've been adding as well as the initial ones
obj[_keys[prop]] = _decode(obj[prop]);
delete obj[prop];
}
}
} else {
obj[prop] = _decode(obj[prop]);
}
}
@fds-github - sorry about the long radio silence on this one. I did incorporate the fix you suggested, but when I tried to run all of the library's tests on IE8, there were some others failing and I think it would be better to advertise support on IE9+.