<commit_before>"use strict";

var Class = require("nodeclass").Class,
    pathUtils = require("path"),
    paths = require("../../shared/helpers/pathHelpers.js"),
    _ = require("underscore");

var Request = new Class({

    "method" : "",
    "path" : "",
    "ids" : {},
    "data" : {},
    "type" : "",

    "__allowedMethods" : ["create", "read", "update", "delete"],

    "init" : function (method, path, data) {

        this.setMethod(method);
        this.setPath(path);
        this.data = data;
    },

    "setMethod" : function(method) {
        //one of the allowed methods
        method = method.toLowerCase();

        if(_.include(this.__allowedMethods, method)){
            this.method = method;
            return;
        }

        throw new Error("Unsupported Method: " + method);
    },

    "setPath" : function(path) {

        //reset ids
        this.ids = {};

        //normalize path to prevent ".." and "."
        path = pathUtils.normalize(path);

        //check traling at the beginning not end
        if(path.charAt(path.length-1) === "/"){
            path = path.substr(0, path.length-1);
        }

        //remove slash at the beginning
        if(path.charAt(0) === "/"){
            path = path.substr(1);
        }

        this.path = path;

        //check for IDs
        var pathParts = path.split("/");

        //determine request-types
        if (paths.filters.onlyServiceURL(path)) {
            this.type = "service";
        }
        else if(paths.filters.onlyValidatorURL(path)) {
            this.type = "validator";
        }
        else {
            throw new Error("(alamid) Cannot find resource '" + path + "': Unknown type '" + pathParts[0] + "'");
        }

        for(var i = 1; i < pathParts.length; i++) {
            if(i % 2 === 0) {
                this.ids[pathParts[i-1]] = pathParts[i];
            }
        }

        //TODO: create request url here - remove ids from url!
    }
});

module.exports = Request;
<commit_msg>- using pathHelpers now for path sanitizing on Request-Class<commit_after>"use strict";

var Class = require("nodeclass").Class,
    pathUtils = require("path"),
    pathHelpers = require("../../shared/helpers/pathHelpers.js"),
    _ = require("underscore");

var Request = new Class({

    "method" : "",
    "path" : "",
    "ids" : {},
    "data" : {},
    "type" : "",

    "__allowedMethods" : ["create", "read", "update", "delete"],

    "init" : function (method, path, data) {

        this.setMethod(method);
        this.setPath(path);
        this.data = data;
    },

    "setMethod" : function(method) {
        //one of the allowed methods
        method = method.toLowerCase();

        if(_.include(this.__allowedMethods, method)){
            this.method = method;
            return;
        }

        throw new Error("Unsupported Method: " + method);
    },

    "setPath" : function(path) {

        //reset ids
        this.ids = {};

        //sanitize the path
        path = pathHelpers.apply.modifier(
            pathHelpers.modifiers.normalize,
            pathHelpers.modifiers.noTrailingSlash,
            pathHelpers.modifiers.noLeadingSlash
        ).on(path);

        this.path = path;

        //check for IDs
        var pathParts = path.split("/");

        //determine request-types
        if (pathHelpers.filters.onlyServiceURL(path)) {
            this.type = "service";
        }
        else if(pathHelpers.filters.onlyValidatorURL(path)) {
            this.type = "validator";
        }
        else {
            throw new Error("(alamid) Cannot find resource '" + path + "': Unknown type '" + pathParts[0] + "'");
        }

        for(var i = 1; i < pathParts.length; i++) {
            if(i % 2 === 0) {
                this.ids[pathParts[i-1]] = pathParts[i];
            }
        }

        //TODO: create request url here - remove ids from url!
    }
});

module.exports = Request;

{'fraction_non_alphanumeric': 0.15532994923857868, 'fraction_numerical': 0.0038071065989847717, 'mean_word_length': 1.829145728643216, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3086393', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1152, 'n_words': 261}