How to use safe-regex - 3 common examples

To help you get started, we’ve selected a few safe-regex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FrankerFaceZ / FrankerFaceZ / src / settings / filters.js View on Github external
createTest(config = {}) {
		const mode = config.mode;
		let title = config.title;

		if ( ! title || ! mode )
			return () => false;

		if ( mode === 'text' )
			title = escape_regex(title);
		else if ( mode === 'glob' )
			title = glob_to_regex(title);
		else if ( mode !== 'raw' )
			return () => false;

		if ( ! safety(title) )
			return () => false;

		let regex;
		try {
			regex = new RegExp(title, `g${config.sensitive ? '' : 'i'}`);
		} catch(err) {
			return () => false;
		}

		return ctx => {
			regex.lastIndex = 0;
			return ctx.title && regex.test(ctx.title);
		}
	},
github Dragory / ZeppelinBot / backend / src / validatorUtils.ts View on Github external
either.chain(t.string.validate(from, to), s => {
      const advancedSyntaxMatch = s.match(regexWithFlags);
      const [regexStr, flags] = advancedSyntaxMatch ? [advancedSyntaxMatch[1], advancedSyntaxMatch[2]] : [s, ""];
      const finalFlags = flags
        .split("")
        .filter(flag => safeRegexAllowedFlags.includes(flag))
        .join("");
      return safeRegex(regexStr) ? t.success(new RegExp(regexStr, finalFlags)) : t.failure(from, to, "Unsafe regex");
    }),
  s => `/${s.source}/${s.flags}`,
github FrankerFaceZ / FrankerFaceZ / src / modules / main_menu / components / term-editor.vue View on Github external
is_safe() {
			const data = this.display,
				t = data.t;

			let v = data.v;

			if ( t === 'text' )
				v = escape_regex(v);

			else if ( t === 'glob' )
				v = glob_to_regex(v);

			return safety(v);
		},

safe-regex

detect possibly catastrophic, exponential-time regular expressions

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis

Popular safe-regex functions