Skip to content

Commit 2551aac

Browse files
authored
Merge pull request github#5236 from asgerf/js/html-invalid-attr-name
Approved by erik-krogh
2 parents 6213c20 + b8e1987 commit 2551aac

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

javascript/extractor/src/com/semmle/js/extractor/HTMLExtractor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ public void handleElement(Element elt, HtmlPopulator.Context context) {
143143
}
144144
}
145145
}
146+
147+
@Override
148+
public boolean shouldExtractAttributes(Element element) {
149+
Attributes attributes = element.getAttributes();
150+
if (attributes == null) return false;
151+
for (Attribute attr : attributes) {
152+
if (!VALID_ATTRIBUTE_NAME.matcher(attr.getName()).matches()) {
153+
return false;
154+
}
155+
}
156+
return true;
157+
}
146158
}
147159

148160
private boolean isAngularTemplateAttributeName(String name) {
@@ -153,6 +165,8 @@ private boolean isAngularTemplateAttributeName(String name) {
153165

154166
private static final Pattern ANGULAR_FOR_LOOP_DECL = Pattern.compile("^ *let +(\\w+) +of(?: +|(?!\\w))(.*)");
155167

168+
private static final Pattern VALID_ATTRIBUTE_NAME = Pattern.compile("\\*?\\[?\\(?[\\w:_\\-]+\\]?\\)?");
169+
156170
/** List of HTML attributes whose value is interpreted as JavaScript. */
157171
private static final Pattern JS_ATTRIBUTE =
158172
Pattern.compile(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
<a href="https://semmle.com" href="https://semmle.com">Semmle</a>
2+
3+
<td {% foo %} {% foo %}></td>

0 commit comments

Comments
 (0)