@@ -11,7 +11,10 @@ private import RegexTreeView
1111 */
1212signature module HostnameRegexpSig< RegexTreeViewSig TreeImpl> {
1313 /** 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+ }
1518
1619 /** A node in the data-flow graph that represents a regular expression pattern. */
1720 class RegExpPatternSource extends DataFlowNode {
@@ -28,12 +31,26 @@ signature module HostnameRegexpSig<RegexTreeViewSig TreeImpl> {
2831 }
2932}
3033
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+
3147/**
3248 * Classes and predicates implementing an analysis on regular expressions
3349 * that match URLs and hostname patterns.
3450 */
3551module Make< RegexTreeViewSig TreeImpl, HostnameRegexpSig< TreeImpl > Specific> {
3652 private import TreeImpl
53+ import Utils
3754
3855 /**
3956 * 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> {
213230 )
214231 }
215232
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-
240233 /** Holds if `term` is one of the transitive left children of a regexp. */
241234 predicate isLeftArmTerm ( RegExpTerm term ) {
242235 term .isRootTerm ( )
@@ -262,10 +255,26 @@ module Make<RegexTreeViewSig TreeImpl, HostnameRegexpSig<TreeImpl> Specific> {
262255 }
263256
264257 /**
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.
266260 */
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+ )
270279 }
271280}
0 commit comments