File tree Expand file tree Collapse file tree 3 files changed +6
-41
lines changed Expand file tree Collapse file tree 3 files changed +6
-41
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- /* tslint:disable:max-line-length */
2
1
import { checkRegex , Rule } from 'rulr' ;
3
2
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' ) ;
25
3
4
+ const regex = / ^ \w + : \/ \/ [ ^ \/ \# \? ] + \/ ? [ ^ \# \? ] * \? ? [ ^ \# ] * \# ? .* $ / i;
26
5
const warningConstructor = createTypeWarning ( 'Internationalized Resource Identifier (IRI)' ) ;
27
6
28
7
export default checkRegex ( regex , warningConstructor ) as Rule ;
Original file line number Diff line number Diff line change @@ -23,4 +23,9 @@ export default (test: Test) => {
23
23
24
24
// tslint:disable-next-line:max-line-length
25
25
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 ) ;
26
31
} ;
You can’t perform that action at this time.
0 commit comments