Skip to content

Commit

Permalink
Fix a bug with sorting of array
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin01 committed Oct 3, 2014
1 parent a507446 commit af33d41
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/helpers/JSONc14n.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ module.exports = {
var keys;
var i;

switch(this.get_type(obj)){
switch(module.exports.get_type(obj)){
case "[object Array]":
json_string = "[";
for(i = 0; i < obj.length; i += 1){
json_string += this.stringify(obj[i]);
if(i < obj.length - 1) {
json_string += ",";
}
var array = [];
for(i = 0; i < obj.length; i += 1) {
array.push(module.exports.stringify(obj[i]));
}
json_string += "]";
array.sort();
json_string = "[" + array.join(',') + "]";
break;
case "[object Object]":
json_string = "{";
keys = Object.keys(obj);
keys.sort();
for(i = 0; i < keys.length; i += 1){
json_string += '"' + keys[i] + '":' + this.stringify(obj[keys[i]]);
json_string += '"' + keys[i] + '":' + module.exports.stringify(obj[keys[i]]);
if(i < keys.length - 1) {
json_string += ",";
}
Expand All @@ -36,11 +34,9 @@ module.exports = {
json_string = "null";
break;
default:
json_string = '"' + obj.toString().replace(/["\\]/g, (function(_this){
return function(character){
return _this.escape_character.apply(_this, [character]);
};
})(this)) + '"';
json_string = '"' + obj.toString().replace(/["\\]/g, function(character) {
return module.exports.escape_character(character);
}) + '"';
}
return json_string;
},
Expand All @@ -52,7 +48,7 @@ module.exports = {
return Object.prototype.toString.call(thing);
},
escape_character: function(character) {
return this.escape_characters[character];
return module.exports.escape_characters[character];
},
escape_characters: {
'"': '\\"',
Expand Down

0 comments on commit af33d41

Please sign in to comment.