marked/test/specs/redos-spec.js
Anders Kaseorg be27472a81 Improve worst-case performance of inline.text regex
The old regex may take quadratic time to scan for potential line
breaks or email addresses starting at every point.  Fix it to avoid
scanning from points that would have been in the middle of a previous
scan.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-04-04 11:13:51 -07:00

25 lines
624 B
JavaScript

const path = require('path');
const fs = require('fs');
const redosDir = path.resolve(__dirname, '../redos');
describe('ReDOS tests', () => {
const files = fs.readdirSync(redosDir);
files.forEach(file => {
if (!file.match(/\.js$/)) {
return;
}
it(file, () => {
const spec = require(path.resolve(redosDir, file));
const before = process.hrtime();
expect(spec).toRender(spec.html);
const elapsed = process.hrtime(before);
if (elapsed[0] > 0) {
const s = (elapsed[0] + elapsed[1] * 1e-9).toFixed(3);
fail(`took too long: ${s}s`);
}
});
});
});