Skip to content

Commit e5e1046

Browse files
authored
Merge pull request #6962 from asgerf/js/template-db-constraint-err
Approved by erik-krogh
2 parents 3bae95a + bfb1da5 commit e5e1046

File tree

4 files changed

+412
-5
lines changed

4 files changed

+412
-5
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,23 @@ public void handleElement(Element elt, HtmlPopulator.Context context) {
8989
}
9090
} else {
9191
Attributes attributes = elt.getAttributes();
92+
boolean attributesAreExtracted = shouldExtractAttributes(elt);
9293
// attributes can be null for directives
9394
if (attributes != null)
9495
for (Attribute attr : attributes) {
9596
// ignore empty attributes
9697
if (attr.getValue() == null || attr.getValue().isEmpty()) continue;
9798

99+
// If attributes are not extracted we can't use the attribute as the parent node.
100+
// In this case, use the enclosing element as the node.
101+
Segment parentSegment = attributesAreExtracted ? attr : elt;
102+
98103
extractTemplateTags(
99104
textualExtractor,
100105
attr.getSource(),
101106
attr.getBegin(),
102107
attr.getEnd(),
103-
() -> context.getNodeLabel(attr));
108+
() -> context.getNodeLabel(parentSegment));
104109

105110
String source = attr.getValue();
106111
int valueStart = attr.getValueSegment().getBegin();
@@ -113,7 +118,7 @@ public void handleElement(Element elt, HtmlPopulator.Context context) {
113118
source,
114119
valueStart,
115120
false /* isTypeScript */,
116-
context.getNodeLabel(attr));
121+
context.getNodeLabel(parentSegment));
117122
} else if (isAngularTemplateAttributeName(attr.getName())) {
118123
// For an attribute *ngFor="let var of EXPR", start parsing at EXPR
119124
int offset = 0;
@@ -133,7 +138,7 @@ public void handleElement(Element elt, HtmlPopulator.Context context) {
133138
source,
134139
valueStart + offset,
135140
false /* isTypeScript */,
136-
context.getNodeLabel(attr));
141+
context.getNodeLabel(parentSegment));
137142
} else if (source.startsWith("javascript:")) {
138143
source = source.substring(11);
139144
extractSnippet(
@@ -144,7 +149,7 @@ public void handleElement(Element elt, HtmlPopulator.Context context) {
144149
source,
145150
valueStart + 11,
146151
false /* isTypeScript */,
147-
context.getNodeLabel(attr));
152+
context.getNodeLabel(parentSegment));
148153
}
149154
}
150155
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Main {
4343
* A version identifier that should be updated every time the extractor changes in such a way that
4444
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4545
*/
46-
public static final String EXTRACTOR_VERSION = "2021-09-01";
46+
public static final String EXTRACTOR_VERSION = "2021-10-25";
4747

4848
public static final Pattern NEWLINE = Pattern.compile("\n");
4949

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<div foo={{foo}}></div>
5+
<div foo={{{foo}}}{{/foo}}/>
6+
<div foo={{#foo}}{{/foo}}/>
7+
<div foo=bar {{#foo}}{{/foo}}/>
8+
<div foo=bar {{#foo}}bar={{baz}}{{/foo}}/>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)