Skip to content

Commit d504e0e

Browse files
committed
fix(iri): Fixes iri regex hanging.
1 parent 4c04fdd commit d504e0e

File tree

3 files changed

+6
-41
lines changed

3 files changed

+6
-41
lines changed

src/helpers/regex.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/regexValues/iri.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
/* tslint:disable:max-line-length */
21
import { checkRegex, Rule } from 'rulr';
32
import { createTypeWarning } from '../warnings/TypeWarning';
4-
import {
5-
escapedChar,
6-
optionalPattern,
7-
capturePattern,
8-
delimitedPattern,
9-
prefixedPattern,
10-
} from '../helpers/regex';
11-
12-
const normChars = `w_~!$&'()*+,;=:-@`.split('').map(escapedChar).join('');
13-
const otherChars = '\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF\\uFFEF-\\uFFFD';
14-
const allChars = `[${normChars}${otherChars}]`;
15-
const allCharsWithDot = `(?:${allChars}|\\.)`;
16-
const extChars = `(?:${allChars}|(?:\\%[a-f0-9][a-f0-9]))`;
17-
18-
const scheme = `(?:(\\w+):\\/\\/)`;
19-
const authority = optionalPattern(capturePattern(delimitedPattern(`${extChars}+`, '.')));
20-
const path = optionalPattern(prefixedPattern('/', `(?:${allCharsWithDot}+\\/?)*`));
21-
const query = optionalPattern(prefixedPattern('?', `${extChars}*`));
22-
const fragment = optionalPattern(prefixedPattern('#', `${extChars}*`));
23-
24-
const regex = new RegExp(`^${scheme}${authority}${path}${query}${fragment}$`, 'i');
253

4+
const regex = /^\w+:\/\/[^\/\#\?]+\/?[^\#\?]*\??[^\#]*\#?.*$/i;
265
const warningConstructor = createTypeWarning('Internationalized Resource Identifier (IRI)');
276

287
export default checkRegex(regex, warningConstructor) as Rule;

src/tests/regexValues/iri.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ export default (test: Test) => {
2323

2424
// tslint:disable-next-line:max-line-length
2525
itsValid('http://some.large.test.string.for.regex/some-large-string/string.html?largeString=largeString&someStrangeText=%D0%9F%D1%81%D0%B5%D0%B2%D0%B4%D0%BE%D1%82%D1%83%D0%B1%D0%B5%D1%80%D0%BA%D1%83%D0%BB%D0%B5%D0%B7', test);
26+
itsValid('https://some.strange.test/tests/very-strange-test-that-hangs-regex/test#test/test"', test);
27+
28+
// Tests from the conformance suite.
29+
itsInvalid('ab=c://should.fail.com', 'not an IRI', test);
30+
itsInvalid('not.a.valid.iri.com/verb', 'not an IRI', test);
2631
};

0 commit comments

Comments
 (0)