Fix netquery textql parser when dealing with IP addresses

This commit is contained in:
Patrick Pacher
2024-03-29 09:35:18 +01:00
parent 0e5b8b2e06
commit 6daea521c3
2 changed files with 60 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ export class Lexer {
}
/** reads a number token */
private readNumber(): Token<TokenType.NUMBER> {
private readNumber(): Token<TokenType.NUMBER> | null {
const start = this._input.pos;
let has_dot = false;
@@ -59,9 +59,10 @@ export class Lexer {
return isDigit(ch);
});
if (!this._input.eof() && isIdentChar(this._input.peek())) {
this._input.revert(number.length + 1);
this._input.croak("invalid number character")
if (!this._input.eof() && !isWhitespace(this._input.peek())) {
this._input.revert(number.length);
return null;
}
return {
@@ -182,13 +183,11 @@ export class Lexer {
return this.readString('\'', true);
}
try {
if (isDigit(ch)) {
return this.readNumber();
if (isDigit(ch)) {
const number = this.readNumber();
if (number !== null) {
return number;
}
} catch (err) {
// we ignore that error here as it may only happen for unqoted strings
// that start with a number.
}
if (ch === ':') {