aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-13 17:49:23 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-13 17:49:23 +0200
commit2d2a2d8982865333e21836ab80bcee1feeff2854 (patch)
tree6e5d156c4cced35f2110866f5bdefce13bc532d1 /src
parent4dc63cee8b20dcba3984019d8fa8221d8117ac35 (diff)
downloadchawan-2d2a2d8982865333e21836ab80bcee1feeff2854.tar.gz
toml: fix bugs in parseNumber
The input c was not considered, so positive/negative/non-decimal number parsing was incorrect.
Diffstat (limited to 'src')
-rw-r--r--src/config/toml.nim27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/config/toml.nim b/src/config/toml.nim
index 82e5aedd..5774f597 100644
--- a/src/config/toml.nim
+++ b/src/config/toml.nim
@@ -354,19 +354,22 @@ type ParsedNumberType = enum
NUMBER_INTEGER, NUMBER_FLOAT, NUMBER_HEX, NUMBER_OCT
proc consumeNumber(state: var TomlParser, c: char): TomlResult =
- var repr = $c
+ var repr = ""
var numType = NUMBER_INTEGER
- if state.has():
- if state.peek(0) == '+' or state.peek(0) == '-':
- repr &= state.consume()
- elif state.peek(0) == '0' and state.has(1):
- let c = state.peek(1)
- if c == 'x':
- numType = NUMBER_HEX
- elif c == 'o':
- numType = NUMBER_OCT
-
- if not state.has() or not isDigit(state.peek(0)):
+ if c == '0' and state.has():
+ let c = state.consume()
+ if c == 'x':
+ numType = NUMBER_HEX
+ elif c == 'o':
+ numType == NUMBER_OCT
+ else:
+ state.reconsume()
+ repr &= c
+ else:
+ repr &= c
+
+ if repr.len > 0 and repr[0] in {'+', '-'} and
+ (not state.has() or not isDigit(state.peek(0))):
return state.err("invalid number")
var was_num = true