<commit_before>import match from './requirejs-finder/match';

const fakeInstance = {
  get _super() {
    return () => {};
  },
  set _super(fn) {},
  execute() {},
};

export default function matchAction(method, url, regex, params) {
  if (url) {
    return match(m =>
      m.prototype &&
        m.prototype.type === method &&
        m.prototype.route === url
    );
  } else if (regex) {
    return match(m => {
      if (!m.prototype || m.prototype.type !== method) {
        return false;
      }
      m.prototype.init.apply(fakeInstance, params || []);
      return fakeInstance.route && (
        typeof regex === 'string'
          ? fakeInstance.route.indexOf(regex) === 0
          : regex.test(fakeInstance.route)<commit_msg>matchAction: avoid crashes when actions attempt to do unexpected things<commit_after>import match from './requirejs-finder/match';

const fakeInstance = {
  get _super() {
    return () => {};
  },
  set _super(fn) {},
  execute() {},
};

export default function matchAction(method, url, regex, params) {
  if (url) {
    return match(m =>
      m.prototype &&
        m.prototype.type === method &&
        m.prototype.route === url
    );
  } else if (regex) {
    return match(m => {
      if (!m.prototype || m.prototype.type !== method) {
        return false;
      }

      try {
        m.prototype.init.apply(fakeInstance, params || []);
      } catch (e) {
        return false;
      }

      return fakeInstance.route && (
        typeof regex === 'string'
          ? fakeInstance.route.indexOf(regex) === 0
          : regex.test(fakeInstance.route)
{'fraction_non_alphanumeric': 0.15480649188514356, 'fraction_numerical': 0.0012484394506866417, 'mean_word_length': 2.360587002096436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1412796', 'n_tokens_mistral': 475, 'n_tokens_neox': 468, 'n_words': 111}