File tree Expand file tree Collapse file tree
semmle/javascript/frameworks
test/query-tests/DOM/TargetBlank Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ predicate hasDynamicHrefHostAttributeValue(DOM::ElementDefinition elem) {
2929 or
3030 exists ( string url | url = attr .getStringValue ( ) |
3131 // fixed string with templating
32- url .regexpMatch ( Templating:: getDelimiterMatchingRegexp ( ) ) and
32+ url .regexpMatch ( Templating:: getDelimiterMatchingRegexpWithPrefix ( "[^?#]*" ) ) and
3333 // ... that does not start with a fixed host or a relative path (common formats)
3434 not url .regexpMatch ( "(?i)((https?:)?//)?[-a-z0-9.]*/.*" ) and
3535 // ... that is not a mailto: link
Original file line number Diff line number Diff line change @@ -39,4 +39,15 @@ module Templating {
3939 string getDelimiterMatchingRegexp ( ) {
4040 result = "(?s).*(" + concat ( "\\Q" + getADelimiter ( ) + "\\E" , "|" ) + ").*"
4141 }
42+
43+ /**
44+ * Gets a regular expression that matches a string containing one
45+ * of the known template delimiters identified by `getADelimiter()`,
46+ * storing it in its first (and only) capture group.
47+ * Where the string prior to the template delimiter matches the regexp `prefix`.
48+ */
49+ bindingset [ prefix]
50+ string getDelimiterMatchingRegexpWithPrefix ( string prefix ) {
51+ result = "(?s)" + prefix + "(" + concat ( "\\Q" + getADelimiter ( ) + "\\E" , "|" ) + ").*"
52+ }
4253}
Original file line number Diff line number Diff line change @@ -29,5 +29,10 @@ <h1>NOT OK, because of dynamic URL</h1>
2929< h1 > OK: mailto is fine.</ h1 >
3030< a target ="_blank " href ="mailto:{{var:mail}} "> mail somone</ a >
3131
32+ < h1 > OK: template elements after # or ? are fine.</ h1 >
33+ < a href ="file.extension?#[% row.href %] " target ="_blank "> Example</ a >
34+ < a href ="file.extension?[% row.href %] " target ="_blank "> Example</ a >
35+ < a href ="file.extension#[% row.href %] " target ="_blank "> Example</ a >
36+
3237</ body >
3338</ html >
You can’t perform that action at this time.
0 commit comments