<commit_before>var qs = require('qs'),
    _  = require('lodash');

var coapRouter = {
  routes : [],
  compilePattern : function (pattern) {
    if(pattern instanceof RegExp) return pattern;
    
    var fragments = pattern.split(/\//);
    return fragments.reduce(
      function (route, fragment, index, fragments) {
        if(fragment.match(/^\:/)) {
          fragment.replace(/^\:/, '');
          route.tokens.push(fragment);
          route.fragments.push('([a-zA-Z0-9-_~\\.%@]+)');
        } else {
          route.fragments.push(fragment);
        }

        if(index === (fragments.length - 1)) route.regexp = route.compileRegExp();
        return route;
      },
      {
        fragments     : [],
        tokens        : [],
        compileRegExp : function () { return new RegExp(this.fragments.join("\\/")); },
        regexp        : ''
      }
    );
  },
  add : function (method, pattern, callback) {
    var route = this.compilePattern(pattern);

    route.method   = method;
    route.pattern  = route.regexp;
    route.callback = callback;

    this.routes.push(route);<commit_msg>corrected regex pattern so that the path is an exact match or nothing<commit_after>var qs = require('qs'),
    _  = require('lodash');

var coapRouter = {
  routes : [],
  compilePattern : function (pattern) {
    if(pattern instanceof RegExp) return pattern;
    
    var fragments = pattern.split(/\//);
    return fragments.reduce(
      function (route, fragment, index, fragments) {
        if(fragment.match(/^\:/)) {
          fragment.replace(/^\:/, '');
          route.tokens.push(fragment);
          route.fragments.push('([a-zA-Z0-9-_~\\.%@]+)');
        } else {
          route.fragments.push(fragment);
        }

        if(index === (fragments.length - 1)) route.regexp = route.compileRegExp();
        return route;
      },
      {
        fragments     : [],
        tokens        : [],
        compileRegExp : function () { return new RegExp(this.fragments.join("\\/") + "$"); },
        regexp        : ''
      }
    );
  },
  add : function (method, pattern, callback) {
    var route = this.compilePattern(pattern);

    route.method   = method;
    route.pattern  = route.regexp;
    route.callback = callback;

    this.routes.push(route);
{'fraction_non_alphanumeric': 0.1619718309859155, 'fraction_numerical': 0.002640845070422535, 'mean_word_length': 2.1094391244870043, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2593923', 'n_tokens_mistral': 688, 'n_tokens_neox': 675, 'n_words': 133}