mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
Fixes bug #25674.
`replace` read `s[i+1]` for a CRLF pair without ensuring `i+1 <
s.len()`, so a value ending in a lone `\\c` (quoted in `writeConfig`)
raised `IndexDefect`.
- Fix: only treat `\\c\\l` when the following character exists.
- Test: `tests/stdlib/tparsecfg.nim` block bug #25674 — fails before
fix, passes after.
(cherry picked from commit 78282b241f)
This commit is contained in:
@@ -556,7 +556,7 @@ proc replace(s: string): string =
|
||||
while i < s.len():
|
||||
if s[i] == '\\':
|
||||
d.add(r"\\")
|
||||
elif s[i] == '\c' and s[i+1] == '\l':
|
||||
elif s[i] == '\c' and i+1 < s.len() and s[i+1] == '\l':
|
||||
d.add(r"\c\l")
|
||||
inc(i)
|
||||
elif s[i] == '\c':
|
||||
|
||||
@@ -130,3 +130,9 @@ block:
|
||||
doAssert dict.getSectionValue(section4, "can_values_be_as_well") == "True"
|
||||
doAssert dict.getSectionValue(section4, "does_that_mean_anything_special") == "False"
|
||||
doAssert dict.getSectionValue(section4, "purpose") == "formatting for readability"
|
||||
|
||||
block: # bug #25674
|
||||
var dict = newConfig()
|
||||
dict.setSectionKey("", "key", "value\c")
|
||||
var s = newStringStream()
|
||||
dict.writeConfig(s)
|
||||
|
||||
Reference in New Issue
Block a user