<commit_before>var stringify_failed_error_message = "stringify json failed!";
var parse_failed_error_message = "parse json failed!";
var circle_private_key = "__circle_private_key_" + new Date().valueOf();
var scan_string = function (str, start) {
    if (str.charAt(start) !== "\"")
        return false;
    var reg = /[^\\]"/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (!match)
        return false;
    return reg.lastIndex;
};
var scan_number = function (str, start) {
    if (str.charAt(start) === "-")
        start++;
    var reg = /(?:0|[1-9]\d*)(?:\.\d*)?/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (!match)
        return false;
    return reg.lastIndex;
};
var scan_null = function (str, start) {
    var reg = /null|false|true/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (match && match.index === start)
        return reg.lastIndex;
    return false;
};
var scan_blank = function (str, start) {
    var reg = /[^\s]/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (match)
        return match.index;
    return str.length;
};
var _safeparse = function (str, start) {
    start = scan_blank(str, start);
    switch (str.charAt(start)) {
        case "\"":
            start = scan_string(str, start);
            break;
        case "{":
            var end = str.length;
            start++;
            if (start >= end) return false;
            while (start < end) {
                start = _safeparse(str, start);
                if (start === false)
                    return start;
                start = scan_blank(str, start);
                if (str.charAt(start) !== ":")
                    return false;
                start++;
                start = _safeparse(str, start);
                if (start === false)
                    return start;
                start = scan_blank(str, start);
                if (str.charAt(start) === ",") {
                    start++;
                    continue;
                }
                if (str.charAt(start) !== "}") {
                    return false;
                }
                start++;
                break;
            }
            break;
        case "[":
            var end = str.length;
            start++;
            if (start >= end) return false;
            while (start < end) {
                start = _safeparse(str, start);
                if (start === false)
                    return start;
                start = scan_blank(str, start);
                if (str.charAt(start) === ",") {
                    start++;
                    continue;
                }
                if (str.charAt(start) !== "]") {
                    return false;
                }
                start++;
                break;
            }
            break;
        case "n":
        case "f":
        case "t":
            start = scan_null(str, start);
            break;
        default:
            start = scan_number(str, start);
    }
    if (start === false)
        return start;
    return scan_blank(str, start);
};
var parse = function (string) {
    string = String(string);
    if (_safeparse(string, 0) === string.length) {
        return new Function("return " + string)();
    } else {
        throw parse_failed_error_message;
    }
};
/**
 * 
 * @param {object} object 
 * @param {function} filter 
 */
var stringify = function (object, filter, space) {
    if (isFunction(object))
        return;
    if (object instanceof Date) {
        object = String(object);
    }
    if (object instanceof Array) {
        if (object[circle_private_key])
            throw stringify_failed_error_message;
        object[circle_private_key] = true;
        var stringified = object.map(function (a) {
            return stringify(a);
        });
        delete object[circle_private_key];
        return "[" + stringified.join(",") + "]";
    }
    if (object instanceof Object) {
        if (object[circle_private_key])
            throw stringify_failed_error_message;
        object[circle_private_key] = true;
        var stringified = [];
        for (var k in object) {
            if (object.hasOwnProperty(k)) {
                var v = stringify(object[k], filter);
                if (isDefined(v))
                    stringified.push("\"" + k.replace(/"/g, "\\\"") + "\":" + v);
            }
        }
        delete object[circle_private_key];
        return "{" + stringified.join(",") + "}";
    }
    if (isString(object)) {
        return "\""+object.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")+"\"";
    }
    return object;
};
var JSON = {
    parse: parse,
    stringify: stringify
};<commit_msg>JSON.stringify漏洞修复<commit_after>var stringify_failed_error_message = "stringify json failed!";
var parse_failed_error_message = "parse json failed!";
var circle_private_key = "__circle_private_key_" + new Date().valueOf();
var scan_string = function (str, start) {
    if (str.charAt(start) !== "\"")
        return false;
    var reg = /[^\\]"/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (!match)
        return false;
    return reg.lastIndex;
};
var scan_number = function (str, start) {
    if (str.charAt(start) === "-")
        start++;
    var reg = /(?:0|[1-9]\d*)(?:\.\d*)?/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (!match)
        return false;
    return reg.lastIndex;
};
var scan_null = function (str, start) {
    var reg = /null|false|true/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (match && match.index === start)
        return reg.lastIndex;
    return false;
};
var scan_blank = function (str, start) {
    var reg = /[^\s]/g;
    reg.lastIndex = start;
    var match = reg.exec(str);
    if (match)
        return match.index;
    return str.length;
};
var _safeparse = function (str, start) {
    start = scan_blank(str, start);
    switch (str.charAt(start)) {
        case "\"":
            start = scan_string(str, start);
            break;
        case "{":
            var end = str.length;
            start++;
            if (start >= end) return false;
            while (start < end) {
                start = _safeparse(str, start);
                if (start === false)
                    return start;
                start = scan_blank(str, start);
                if (str.charAt(start) !== ":")
                    return false;
                start++;
                start = _safeparse(str, start);
                if (start === false)
                    return start;
                start = scan_blank(str, start);
                if (str.charAt(start) === ",") {
                    start++;
                    continue;
                }
                if (str.charAt(start) !== "}") {
                    return false;
                }
                start++;
                break;
            }
            break;
        case "[":
            var end = str.length;
            start++;
            if (start >= end) return false;
            while (start < end) {
                start = _safeparse(str, start);
                if (start === false)
                    return start;
                start = scan_blank(str, start);
                if (str.charAt(start) === ",") {
                    start++;
                    continue;
                }
                if (str.charAt(start) !== "]") {
                    return false;
                }
                start++;
                break;
            }
            break;
        case "n":
        case "f":
        case "t":
            start = scan_null(str, start);
            break;
        default:
            start = scan_number(str, start);
    }
    if (start === false)
        return start;
    return scan_blank(str, start);
};
var parse = function (string) {
    string = String(string);
    if (_safeparse(string, 0) === string.length) {
        return new Function("return " + string)();
    } else {
        throw parse_failed_error_message;
    }
};
/**
 * 
 * @param {object} object 
 * @param {function} filter 
 */
var stringify = function (object, filter, space) {
    if (isFunction(object))
        return;
    if (object instanceof Date) {
        object = String(object);
    }
    if (object instanceof Array) {
        if (object[circle_private_key])
            throw stringify_failed_error_message;
        object[circle_private_key] = true;
        var stringified = object.map(function (a) {
            return stringify(a);
        });
        delete object[circle_private_key];
        return "[" + stringified.join(",") + "]";
    }
    if (object instanceof Object) {
        if (object[circle_private_key])
            throw stringify_failed_error_message;
        object[circle_private_key] = true;
        var stringified = [];
        for (var k in object) {
            if (object.hasOwnProperty(k)) {
                var v = stringify(object[k], filter);
                if (isDefined(v))
                    stringified.push("\"" + k.replace(/[\\"]/g, "\\$1") + "\":" + v);
            }
        }
        delete object[circle_private_key];
        return "{" + stringified.join(",") + "}";
    }
    if (isString(object)) {
        return "\""+object.replace(/[\\"]/g, "\\$1")+"\"";
    }
    return object;
};
var JSON = {
    parse: parse,
    stringify: stringify
};
{'fraction_non_alphanumeric': 0.1413873568095036, 'fraction_numerical': 0.0010606703436571913, 'mean_word_length': 1.5360408821947285, 'pattern_counts': {'":': 16, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2053431', 'n_tokens_mistral': 2777, 'n_tokens_neox': 2677, 'n_words': 653}