Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of invalid UTF-8 #11968

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/pure/htmlparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ proc runeToEntity*(rune: Rune): string =
runnableExamples:
import unicode
doAssert runeToEntity(Rune(0)) == ""
doAssert runeToEntity(Rune(-1)) == ""
doAssert runeToEntity("Ü".runeAt(0)) == "#220"
doAssert runeToEntity("∈".runeAt(0)) == "#8712"
if rune.ord <= 0: result = ""
Expand Down Expand Up @@ -1888,7 +1887,7 @@ proc entityToUtf8*(entity: string): string =
doAssert entityToUtf8("#X3a3") == sigma
let rune = entityToRune(entity)
if rune.ord <= 0: result = ""
else: result = toUTF8(rune)
else: result = toUtf8(rune)

proc addNode(father, son: XmlNode) =
if son != nil: add(father, son)
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/parsejson.nim
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ proc parseString(my: var JsonParser): TokKind =
else:
break
else:
add(my.a, toUTF8(Rune(r)))
add(my.a, toUtf8(Rune(r)))
else:
# don't bother with the error
add(my.a, my.buf[pos])
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/parsexml.nim
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ proc parseEntity(my: var XmlParser, dest: var string) =
while my.buf[pos] in {'0'..'9'}:
r = r * 10 + (ord(my.buf[pos]) - ord('0'))
inc(pos)
add(dest, toUTF8(Rune(r)))
add(dest, toUtf8(Rune(r)))
elif my.buf[pos] == 'l' and my.buf[pos+1] == 't' and my.buf[pos+2] == ';':
add(dest, '<')
inc(pos, 2)
Expand Down
4 changes: 2 additions & 2 deletions lib/pure/terminal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ proc getch*(): char =
discard fd.tcSetAttr(TCSADRAIN, addr oldMode)

when defined(windows):
from unicode import toUTF8, Rune, runeLenAt
from unicode import toUtf8, Rune, runeLenAt

proc readPasswordFromStdin*(prompt: string, password: var TaintedString):
bool {.tags: [ReadIOEffect, WriteIOEffect].} =
Expand All @@ -792,7 +792,7 @@ when defined(windows):
# https://github.com/nim-lang/Nim/issues/7764
continue
else:
password.string.add(toUTF8(c.Rune))
password.string.add(toUtf8(c.Rune))
stdout.write "\n"

else:
Expand Down
Loading