mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-05 21:44:46 +00:00
prevent null characters in $ on collections of char
This commit is contained in:
@@ -2425,6 +2425,14 @@ proc collectionToString[T](x: T, prefix, separator, suffix: string): string =
|
||||
result.add "nil"
|
||||
else:
|
||||
result.add($value)
|
||||
# prevent temporary string allocation
|
||||
elif compiles(result.add(value)):
|
||||
# don't insert '\0' characters into the result string
|
||||
when value is char:
|
||||
if value != '\0':
|
||||
result.add(value)
|
||||
else:
|
||||
result.add(value)
|
||||
else:
|
||||
result.add($value)
|
||||
|
||||
@@ -3307,7 +3315,6 @@ proc `$`*[T, IDX](x: array[IDX, T]): string =
|
||||
## generic ``$`` operator for arrays that is lifted from the components
|
||||
collectionToString(x, "[", ", ", "]")
|
||||
|
||||
|
||||
proc quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} =
|
||||
## a shorthand for ``echo(errormsg); quit(errorcode)``.
|
||||
echo(errormsg)
|
||||
|
||||
Reference in New Issue
Block a user