mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
fix location off-by-ones with regexp parsing
This commit is contained in:
@@ -589,7 +589,7 @@ public class ASTExtractor {
|
||||
|
||||
trapwriter.addTuple("literals", valueString, source, key);
|
||||
Position start = nd.getLoc().getStart();
|
||||
com.semmle.util.locations.Position startPos = new com.semmle.util.locations.Position(start.getLine(), start.getColumn(), start.getOffset());
|
||||
com.semmle.util.locations.Position startPos = new com.semmle.util.locations.Position(start.getLine(), start.getColumn() + 1 /* Convert from 0-based to 1-based. */, start.getOffset());
|
||||
|
||||
if (nd.isRegExp()) {
|
||||
OffsetTranslation offsets = new OffsetTranslation();
|
||||
@@ -867,7 +867,7 @@ public class ASTExtractor {
|
||||
}
|
||||
OffsetTranslation offsets = concatResult.snd();
|
||||
Position start = nd.getLoc().getStart();
|
||||
com.semmle.util.locations.Position startPos = new com.semmle.util.locations.Position(start.getLine(), start.getColumn(), start.getOffset());
|
||||
com.semmle.util.locations.Position startPos = new com.semmle.util.locations.Position(start.getLine(), start.getColumn() + 1 /* Convert from 0-based to 1-based. */, start.getOffset());
|
||||
SourceMap sourceMap = SourceMap.legacyWithStartPos(SourceMap.fromString(nd.getLoc().getSource()).offsetBy(0, offsets), startPos);
|
||||
regexpExtractor.extract(foldedString, sourceMap, nd, true);
|
||||
return;
|
||||
|
||||
@@ -121,10 +121,12 @@ public class RegExpExtractor {
|
||||
}
|
||||
|
||||
public void emitLocation(SourceElement term, Label lbl) {
|
||||
int sl = sourceMap.getStart(term.getLoc().getStart().getColumn()).getLine();
|
||||
int sc = sourceMap.getStart(term.getLoc().getStart().getColumn()).getColumn() + 1; // convert to 1-based
|
||||
int el = sourceMap.getEnd(term.getLoc().getEnd().getColumn()).getLine();
|
||||
int ec = sourceMap.getEnd(term.getLoc().getEnd().getColumn()).getColumn() - 1; // convert to inclusive
|
||||
int start = term.getLoc().getStart().getColumn();
|
||||
int sl = sourceMap.getStart(start).getLine();
|
||||
int sc = sourceMap.getStart(start).getColumn();
|
||||
int end = term.getLoc().getEnd().getColumn();
|
||||
int el = sourceMap.getStart(end).getLine();
|
||||
int ec = sourceMap.getStart(end).getColumn() - 1; // convert to inclusive
|
||||
locationManager.emitSnippetLocation(lbl, sl, sc, el, ec);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user