<commit_before>///[readme.md]

function getRequestData(maxSize, raw, callback){

    if(typeof maxSize !== 'number'){
        callback = raw;
        raw = maxSize;
        maxSize = null;
    }

    if(typeof raw !== 'boolean'){
        callback = raw;
        raw = null;
    }

    return function(){
        var data = '',
            args = Array.prototype.slice.call(arguments),
            request = args[0],
            response = args[1];

        request.on('data',function(chunk){
            if(data.length > (maxSize || getRequestData.maxRequestSize || 1e6)){
                // flood attack, kill.
                request.connection.destroy();
            }
            data += chunk.toString();
        });

        request.on('end', function(){
            callback.apply(null, args.concat([raw ? data : data ? JSON.parse(data) : undefined]));
        });
    };
}
module.exports = getRequestData;<commit_msg>Fixes bug where non-json string will cause a crash<commit_after>///[readme.md]

function getRequestData(maxSize, raw, callback){

    if(typeof maxSize !== 'number'){
        callback = raw;
        raw = maxSize;
        maxSize = null;
    }

    if(typeof raw !== 'boolean'){
        callback = raw;
        raw = null;
    }

    return function(){
        var data = '',
            args = Array.prototype.slice.call(arguments),
            request = args[0],
            response = args[1];

        request.on('data',function(chunk){
            if(data.length > (maxSize || getRequestData.maxRequestSize || 1e6)){
                // flood attack, kill.
                request.connection.destroy();
            }
            data += chunk.toString();
        });

        request.on('end', function(){
            var newArg;
            if (raw) {
                newArg = data;
            } else if (data) {
                try {
                    newArg = JSON.parse(data);
                } catch (e) {
                    //Invalid json
                    newArg = undefined;
                }
            }
            callback.apply(null, args.concat([newArg]));
        });
    };
}
module.exports = getRequestData;
{'fraction_non_alphanumeric': 0.1361111111111111, 'fraction_numerical': 0.003703703703703704, 'mean_word_length': 1.5157159487776484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '297837', 'n_tokens_mistral': 595, 'n_tokens_neox': 570, 'n_words': 125}