<commit_before>// Template: JavaScriptFilter.js
var block = function (haystack, filters) {
  filters.some(function (jsonRegex) {
    // Create a regex from the json string.
    var f = new RegExp(jsonRegex.rule, jsonRegex.flags);
    print('regex',f);
    var hit = f.exec(haystack.trim());
    if (hit) {
      print('found', hit[0], haystack);
      context.setVariable('FILTER.block', true);
      return true;
    }
  });
};

elements.forEach(function (element) {
  var filters = element.filters;
  var decodedUrl = decodeURIComponent(context.proxyRequest.url);
  var params = parse(decodedUrl.substr(decodedUrl.indexOf('?')));
  if (element.element === 'QueryParam') {
    Object.keys(params).forEach(function (key) {
      var val = params[key];<commit_msg>assume invalid qs if qs cannot be parsed<commit_after>// Template: JavaScriptFilter.js
var block = function (haystack, filters) {
  filters.some(function (jsonRegex) {
    // Create a regex from the json string.
    var f = new RegExp(jsonRegex.rule, jsonRegex.flags);
    print('regex',f);
    var hit = f.exec(haystack.trim());
    if (hit) {
      print('found', hit[0], haystack);
      context.setVariable('FILTER.block', true);
      return true;
    }
  });
};

elements.forEach(function (element) {
  var filters = element.filters;
  var decodedUrl = decodeURIComponent(context.proxyRequest.url);
  var params;
  try {
     params = parse(decodedUrl.substr(decodedUrl.indexOf('?')));
  } catch (error) {
    print('could not parse querystring', error);
    context.setVariable('FILTER.block', true);
    return true;
  }  
  if (element.element === 'QueryParam') {
    Object.keys(params).forEach(function (key) {
      var val = params[key];
{'fraction_non_alphanumeric': 0.14827787507297138, 'fraction_numerical': 0.0011675423234092236, 'mean_word_length': 3.657608695652174, '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': '4255523', 'n_tokens_mistral': 532, 'n_tokens_neox': 528, 'n_words': 128}