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 */
21import { checkRegex , Rule } from 'rulr' ;
32import { 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;
265const warningConstructor = createTypeWarning ( 'Internationalized Resource Identifier (IRI)' ) ;
276
287export default checkRegex ( regex , warningConstructor ) as Rule ;
Original file line number Diff line number Diff 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} ;
You can’t perform that action at this time.
0 commit comments