-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Share XML discard predicates #20873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Share XML discard predicates #20873
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| overlay[local] | ||
| module; | ||
|
|
||
| /** | ||
| * A local predicate that always holds for the overlay variant and never holds for the base variant. | ||
| * This is used to define local predicates that behave differently for the base and overlay variant. | ||
| */ | ||
| private predicate isOverlay() { databaseMetadata("isOverlay", "true") } | ||
|
|
||
| private @file getXmlFile(@xmllocatable locatable) { | ||
| exists(@location_default location | xmllocations(locatable, location) | | ||
| locations_default(location, result, _, _, _, _) | ||
| ) | ||
| } | ||
|
|
||
| private @file getXmlFileInBase(@xmllocatable locatable) { | ||
| not isOverlay() and | ||
| result = getXmlFile(locatable) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML | ||
| * extractor. | ||
| */ | ||
| private predicate overlayXmlExtracted(@file file) { | ||
| isOverlay() and | ||
| exists(@xmllocatable locatable | | ||
| not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given XML `locatable` should be discarded, because it is part of the overlay base | ||
| * and is in a file that was also extracted as part of the overlay database. | ||
| */ | ||
| overlay[discard_entity] | ||
| private predicate discardXmlLocatable(@xmllocatable locatable) { | ||
| exists(@file file | file = getXmlFileInBase(locatable) | | ||
| exists(string path | files(file, path) | overlayChangedFiles(path)) | ||
| or | ||
| // The HTML/XML extractor is currently not incremental and may extract more files than those | ||
| // included in overlayChangedFiles. | ||
| overlayXmlExtracted(file) | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| overlay[local] | ||
| module; | ||
|
|
||
| /** | ||
| * A local predicate that always holds for the overlay variant and never holds for the base variant. | ||
| * This is used to define local predicates that behave differently for the base and overlay variant. | ||
| */ | ||
| private predicate isOverlay() { databaseMetadata("isOverlay", "true") } | ||
|
|
||
| private @file getXmlFile(@xmllocatable locatable) { | ||
| exists(@location_default location | xmllocations(locatable, location) | | ||
| locations_default(location, result, _, _, _, _) | ||
| ) | ||
| } | ||
|
|
||
| private @file getXmlFileInBase(@xmllocatable locatable) { | ||
| not isOverlay() and | ||
| result = getXmlFile(locatable) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML | ||
| * extractor. | ||
| */ | ||
| private predicate overlayXmlExtracted(@file file) { | ||
| isOverlay() and | ||
| exists(@xmllocatable locatable | | ||
| not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given XML `locatable` should be discarded, because it is part of the overlay base | ||
| * and is in a file that was also extracted as part of the overlay database. | ||
| */ | ||
| overlay[discard_entity] | ||
| private predicate discardXmlLocatable(@xmllocatable locatable) { | ||
| exists(@file file | file = getXmlFileInBase(locatable) | | ||
| exists(string path | files(file, path) | overlayChangedFiles(path)) | ||
| or | ||
| // The HTML/XML extractor is currently not incremental and may extract more files than those | ||
| // included in overlayChangedFiles. | ||
| overlayXmlExtracted(file) | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| overlay[local] | ||
| module; | ||
|
|
||
| /** | ||
| * A local predicate that always holds for the overlay variant and never holds for the base variant. | ||
| * This is used to define local predicates that behave differently for the base and overlay variant. | ||
| */ | ||
| private predicate isOverlay() { databaseMetadata("isOverlay", "true") } | ||
|
|
||
| private @file getXmlFile(@xmllocatable locatable) { | ||
| exists(@location_default location | xmllocations(locatable, location) | | ||
| locations_default(location, result, _, _, _, _) | ||
| ) | ||
| } | ||
|
|
||
| private @file getXmlFileInBase(@xmllocatable locatable) { | ||
| not isOverlay() and | ||
| result = getXmlFile(locatable) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML | ||
| * extractor. | ||
| */ | ||
| private predicate overlayXmlExtracted(@file file) { | ||
| isOverlay() and | ||
| exists(@xmllocatable locatable | | ||
| not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given XML `locatable` should be discarded, because it is part of the overlay base | ||
| * and is in a file that was also extracted as part of the overlay database. | ||
| */ | ||
| overlay[discard_entity] | ||
| private predicate discardXmlLocatable(@xmllocatable locatable) { | ||
| exists(@file file | file = getXmlFileInBase(locatable) | | ||
| exists(string path | files(file, path) | overlayChangedFiles(path)) | ||
| or | ||
| // The HTML/XML extractor is currently not incremental and may extract more files than those | ||
| // included in overlayChangedFiles. | ||
| overlayXmlExtracted(file) | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
javascript/ql/lib/semmle/javascript/internal/OverlayXml.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| overlay[local] | ||
| module; | ||
|
|
||
| /** | ||
| * A local predicate that always holds for the overlay variant and never holds for the base variant. | ||
| * This is used to define local predicates that behave differently for the base and overlay variant. | ||
| */ | ||
| private predicate isOverlay() { databaseMetadata("isOverlay", "true") } | ||
|
|
||
| private @file getXmlFile(@xmllocatable locatable) { | ||
| exists(@location_default location | xmllocations(locatable, location) | | ||
| locations_default(location, result, _, _, _, _) | ||
| ) | ||
| } | ||
|
|
||
| private @file getXmlFileInBase(@xmllocatable locatable) { | ||
| not isOverlay() and | ||
| result = getXmlFile(locatable) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML | ||
| * extractor. | ||
| */ | ||
| private predicate overlayXmlExtracted(@file file) { | ||
| isOverlay() and | ||
| exists(@xmllocatable locatable | | ||
| not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if the given XML `locatable` should be discarded, because it is part of the overlay base | ||
| * and is in a file that was also extracted as part of the overlay database. | ||
| */ | ||
| overlay[discard_entity] | ||
| private predicate discardXmlLocatable(@xmllocatable locatable) { | ||
| exists(@file file | file = getXmlFileInBase(locatable) | | ||
| exists(string path | files(file, path) | overlayChangedFiles(path)) | ||
| or | ||
| // The HTML/XML extractor is currently not incremental and may extract more files than those | ||
| // included in overlayChangedFiles. | ||
| overlayXmlExtracted(file) | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all languages extract
@fileusing named trap ids? Because if not, then this identification change from string to@filewon't work. I'm guessing that they do, but this is a subtle change, so I figured it would be best to check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
stringis the more robust option, let's go with that.