@@ -11,7 +11,10 @@ private import RegexTreeView
11
11
*/
12
12
signature module HostnameRegexpSig< RegexTreeViewSig TreeImpl> {
13
13
/** A node in the data-flow graph. */
14
- class DataFlowNode ;
14
+ class DataFlowNode {
15
+ /** Gets a string representation of this node. */
16
+ string toString ( ) ;
17
+ }
15
18
16
19
/** A node in the data-flow graph that represents a regular expression pattern. */
17
20
class RegExpPatternSource extends DataFlowNode {
@@ -28,12 +31,26 @@ signature module HostnameRegexpSig<RegexTreeViewSig TreeImpl> {
28
31
}
29
32
}
30
33
34
+ /**
35
+ * Utility predicates and classes that doesn't depend on any signature.
36
+ */
37
+ module Utils {
38
+ /**
39
+ * Gets a pattern that matches common top-level domain names in lower case.
40
+ */
41
+ string getACommonTld ( ) {
42
+ // according to ranking by http://google.com/search?q=site:.<<TLD>>
43
+ result = "(?:com|org|edu|gov|uk|net|io)(?![a-z0-9])"
44
+ }
45
+ }
46
+
31
47
/**
32
48
* Classes and predicates implementing an analysis on regular expressions
33
49
* that match URLs and hostname patterns.
34
50
*/
35
51
module Make< RegexTreeViewSig TreeImpl, HostnameRegexpSig< TreeImpl > Specific> {
36
52
private import TreeImpl
53
+ import Utils
37
54
38
55
/**
39
56
* Holds if the given constant is unlikely to occur in the origin part of a URL.
@@ -213,30 +230,6 @@ module Make<RegexTreeViewSig TreeImpl, HostnameRegexpSig<TreeImpl> Specific> {
213
230
)
214
231
}
215
232
216
- /**
217
- * Holds if `regexp` is a regular expression that is likely to match a hostname,
218
- * but the pattern is incomplete and may match more hosts than intended.
219
- */
220
- predicate incompleteHostnameRegExp (
221
- RegExpSequence hostSequence , string message , Specific:: DataFlowNode aux , string label
222
- ) {
223
- exists ( Specific:: RegExpPatternSource re , RegExpTerm regexp , string msg , string kind |
224
- regexp = re .getRegExpTerm ( ) and
225
- isIncompleteHostNameRegExpPattern ( regexp , hostSequence , msg ) and
226
- (
227
- if re .getAParse ( ) != re
228
- then (
229
- kind = "string, which is used as a regular expression $@," and
230
- aux = re .getAParse ( )
231
- ) else (
232
- kind = "regular expression" and aux = re
233
- )
234
- )
235
- |
236
- message = "This " + kind + " " + msg and label = "here"
237
- )
238
- }
239
-
240
233
/** Holds if `term` is one of the transitive left children of a regexp. */
241
234
predicate isLeftArmTerm ( RegExpTerm term ) {
242
235
term .isRootTerm ( )
@@ -262,10 +255,26 @@ module Make<RegexTreeViewSig TreeImpl, HostnameRegexpSig<TreeImpl> Specific> {
262
255
}
263
256
264
257
/**
265
- * Gets a pattern that matches common top-level domain names in lower case.
258
+ * Holds if `regexp` is a regular expression that is likely to match a hostname,
259
+ * but the pattern is incomplete and may match more hosts than intended.
266
260
*/
267
- string getACommonTld ( ) {
268
- // according to ranking by http://google.com/search?q=site:.<<TLD>>
269
- result = "(?:com|org|edu|gov|uk|net|io)(?![a-z0-9])"
261
+ predicate incompleteHostnameRegExp (
262
+ RegExpSequence hostSequence , string message , Specific:: DataFlowNode aux , string label
263
+ ) {
264
+ exists ( Specific:: RegExpPatternSource re , RegExpTerm regexp , string msg , string kind |
265
+ regexp = re .getRegExpTerm ( ) and
266
+ isIncompleteHostNameRegExpPattern ( regexp , hostSequence , msg ) and
267
+ (
268
+ if re .getAParse ( ) != re
269
+ then (
270
+ kind = "string, which is used as a regular expression $@," and
271
+ aux = re .getAParse ( )
272
+ ) else (
273
+ kind = "regular expression" and aux = re
274
+ )
275
+ )
276
+ |
277
+ message = "This " + kind + " " + msg and label = "here"
278
+ )
270
279
}
271
280
}
0 commit comments