source: trip-planner-front/node_modules/safe-regex/readme.markdown@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[6a3a178]1# safe-regex
2
3detect potentially
4[catastrophic](http://regular-expressions.mobi/catastrophic.html)
5[exponential-time](http://perlgeek.de/blog-en/perl-tips/in-search-of-an-exponetial-regexp.html)
6regular expressions by limiting the
7[star height](https://en.wikipedia.org/wiki/Star_height) to 1
8
9WARNING: This module merely *seems* to work given all the catastrophic regular
10expressions I could find scouring the internet, but I don't have enough of a
11background in automata to be absolutely sure that this module will catch all
12exponential-time cases.
13
14[![browser support](https://ci.testling.com/substack/safe-regex.png)](https://ci.testling.com/substack/safe-regex)
15
16[![build status](https://secure.travis-ci.org/substack/safe-regex.png)](http://travis-ci.org/substack/safe-regex)
17
18# example
19
20``` js
21var safe = require('safe-regex');
22var regex = process.argv.slice(2).join(' ');
23console.log(safe(regex));
24```
25
26```
27$ node safe.js '(x+x+)+y'
28false
29$ node safe.js '(beep|boop)*'
30true
31$ node safe.js '(a+){10}'
32false
33$ node safe.js '\blocation\s*:[^:\n]+\b(Oakland|San Francisco)\b'
34true
35```
36
37# methods
38
39``` js
40var safe = require('safe-regex')
41```
42
43## var ok = safe(re, opts={})
44
45Return a boolean `ok` whether or not the regex `re` is safe and not possibly
46catastrophic.
47
48`re` can be a `RegExp` object or just a string.
49
50If the `re` is a string and is an invalid regex, returns `false`.
51
52* `opts.limit` - maximum number of allowed repetitions in the entire regex.
53Default: `25`.
54
55# install
56
57With [npm](https://npmjs.org) do:
58
59```
60npm install safe-regex
61```
62
63# license
64
65MIT
Note: See TracBrowser for help on using the repository browser.