-
Notifications
You must be signed in to change notification settings - Fork 190
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
Results whose location.endColumn == 0 are incorrectly linked #999
Comments
Thanks for your bug report. I am chatting with the yaml extractor maintainers to determine a way forward. |
Regardless of whether the YAML extractor should emit locations whose |
I chatted with the yaml extractor maintainers, and I now have a better idea of what is happening. 0-based column indexes are not explicitly supported in the CodeQL CLI, but they do mostly work in that they match the last character of the previous line. Similarly, specifying a column offset after the end of the line starts matching on the next line. This is all easy enough to do inside of the CLI since it has easy access to the full file contents. To be clear, the docs indicate that both line and column offsets are 1-based. https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/ Using 0 or values greater than the end column work, but it is undocumented. Several things to note here:
So, I don't think this is a bug in the YAML extractor. It's possibly a bug in the CLI, but it's probably too late to change. At the very least, the documentation page should change. Also, the vscode extension should avoid failing if it receives a surprising location. It should translate it into something it can handle even if it is not precisely what is requested. If it turns out there is a need to handle locations exactly the same way that the CLI does, we can look into that later. |
Sounds like a good approach to me! |
Previously, positions with end column of 0 were rejected by the extension. CodeQL positions are supposed to be 1-based, but the CLI does handle 0-based and negative positions by using character offsets from the current line start. Instead of rejecting these kinds of positions, the extension should handle them as gracefully as possible. Fixes #999
* Add leniency in how positions are handled Previously, positions with end column of 0 were rejected by the extension. CodeQL positions are supposed to be 1-based, but the CLI does handle 0-based and negative positions by using character offsets from the current line start. Instead of rejecting these kinds of positions, the extension should handle them as gracefully as possible. Fixes #999 * Add changelog entry
* Add leniency in how positions are handled Previously, positions with end column of 0 were rejected by the extension. CodeQL positions are supposed to be 1-based, but the CLI does handle 0-based and negative positions by using character offsets from the current line start. Instead of rejecting these kinds of positions, the extension should handle them as gracefully as possible. Fixes #999 * Update package lock
When writing queries to explore YAML files (using Javascript's YAML.qll library), top-level YAMLMapping instances always have their
endColumn
set to zero. This is not an issue, as I'd expect it to have the selection region end at the beginning ofendLine
with no characters on that line selected, just the newline from the previous line and stuff before that. The problem is thatendColumn > 0
is explicitly checked in the extension's source code, and zero is considered an invalid value forendColumn
:vscode-codeql/extensions/ql-vscode/src/pure/bqrs-utils.ts
Line 87 in 3e0ea1b
In all of these cases,
endLine
>startLine
andendColumn
== 0.Version
CodeQL extension version: 1.5.6 CodeQL CLI version: 2.7.0 Platform: darwin x64
To reproduce
Run this query on any database from any language (tested on Python, should also work for Javascript at least):
Expected behavior
Clicking on either result in the table links to the source file with the entire second line highlighted. What actually happens is that the
BadLocation
result links just to the top of the file, whereas theGoodLocation
result goes to the second line completely highlighted and the first character of the third line highlighted.If the intent of that check is to ensure the end is past the start, then it would make more sense to do it like:
The text was updated successfully, but these errors were encountered: