Reputation: 6707
this code fails randomly when input comes from specific sources, it works usually OK:
var str = input;
var lines = str.split("¤");
var map = {};
for(var i = 0; i < lines.length; i++) { var pieces = lines[i].split("=");
map[pieces[0]] = pieces[1];}
for example this input data does not create MAP at all, there is just one map entry:
"[core]¤student_id=teach54yuy63v¤student_name=Demo, teacher¤credit=c¤lesson_location=¤lesson_status=n,a¤path=¤score=¤time=00:00:00¤[Core_Lesson]¤tmreal_status=n,a¤tmreal_score=¤¤¤[Core_Vendor]¤¤[Objectives_Status]¤¤"
this data works:
[core]¤student_id=169yyuy63v¤student_name=, Si¤credit=c¤lesson_location=1¤lesson_status=n,a¤path=¤score=¤time=00:00:00¤[Core_Lesson]¤real_status=i¤real_score=¤talhits=int:
Upvotes: 1
Views: 348
Reputation: 700272
You get an error when you try to access the second item from splitting "[core]" on "=".
You would need a check after splitting on "=" that you actually got a key and a value.
var str = input;
var lines = str.split("¤");
var map = {};
for (var i = 0; i < lines.length; i++) {
var pieces = lines[i].split("=");
if (pieces.length == 2) {
map[pieces[0]] = pieces[1];
}
}
Upvotes: 1
Reputation:
It has to do with encoding. Maybe some resources use ASCII, some UTF. Convert, or make sure all resources have the same encoding.
Upvotes: 1