File tree Expand file tree Collapse file tree
swift/ql/test/library-tests/regex Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ // --- stubs ---
3+
4+ struct URL {
5+ init ? ( string: String ) { }
6+ }
7+
8+ struct AnyRegexOutput {
9+ }
10+
11+ protocol RegexComponent {
12+ }
13+
14+ struct Regex < Output> : RegexComponent {
15+ struct Match {
16+ }
17+
18+ init ( _ pattern: String ) throws where Output == AnyRegexOutput { }
19+
20+ func firstMatch( in string: String ) throws -> Regex < Output > . Match ? { return nil }
21+
22+ typealias RegexOutput = Output
23+ }
24+
25+ extension String {
26+ init ( contentsOf: URL ) {
27+ let data = " "
28+ self . init ( data)
29+ }
30+ }
31+
32+ // --- tests ---
33+
34+ func myRegexpVariantsTests( myUrl: URL ) throws {
35+ let tainted = String ( contentsOf: myUrl) // tainted
36+ let untainted = " abcdef "
37+
38+ _ = try Regex ( " .* " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted
39+
40+ _ = try Regex ( " a*b " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted
41+ _ = try Regex ( " (a*)b " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted
42+ _ = try Regex ( " (a)*b " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted
43+ _ = try Regex ( " (a*)*b " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted MISSING: redos-vulnerable=
44+ _ = try Regex ( " ((a*)*b) " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted MISSING: redos-vulnerable=
45+
46+ _ = try Regex ( " (a|aa?)b " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted
47+ _ = try Regex ( " (a|aa?)*b " ) . firstMatch ( in: tainted) // $ regex="call to Regex<AnyRegexOutput>.init(_:)" input=tainted MISSING: redos-vulnerable=
48+
49+ // TODO: test more variant expressions.
50+ }
You can’t perform that action at this time.
0 commit comments