Skip to content

Commit 734cba7

Browse files
committed
Go: add discard predicates for XML entities
This is adapted from the implementation for Java. Since the HTML/XML extractor is not (yet) incremental, it will extract files that were not in the diff. These discard predicates are intended to cope with that, while also being robust against a future version where the extractor *is* overlay-aware.
1 parent 10fa1d6 commit 734cba7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

go/ql/lib/semmle/go/Overlay.qll

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,40 @@ private predicate discardLocatable(@locatable locatable) {
5050
discardableLocatable(file, locatable) and discardableFile(path)
5151
)
5252
}
53+
54+
private @file getXmlFile(@xmllocatable locatable) {
55+
exists(@location_default location | xmllocations(locatable, location) |
56+
locations_default(location, result, _, _, _, _)
57+
)
58+
}
59+
60+
private @file getXmlFileInBase(@xmllocatable locatable) {
61+
not isOverlay() and
62+
result = getXmlFile(locatable)
63+
}
64+
65+
/**
66+
* Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML
67+
* extractor.
68+
*/
69+
private predicate overlayXmlExtracted(@file file) {
70+
isOverlay() and
71+
exists(@xmllocatable locatable |
72+
not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable)
73+
)
74+
}
75+
76+
/**
77+
* Holds if the given XML `locatable` should be discarded, because it is part of the overlay base
78+
* and is in a file that was also extracted as part of the overlay database.
79+
*/
80+
overlay[discard_entity]
81+
private predicate discardXmlLocatable(@xmllocatable locatable) {
82+
exists(@file file | file = getXmlFileInBase(locatable) |
83+
exists(string path | files(file, path) | overlayChangedFiles(path))
84+
or
85+
// The HTML/XML extractor is currently not incremental and may extract more files than those
86+
// included in overlayChangedFiles.
87+
overlayXmlExtracted(file)
88+
)
89+
}

0 commit comments

Comments
 (0)