diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-15 17:53:26 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-15 17:53:26 +0100 |
commit | 683cf2ee3ce2fbf6304839d3b68236228fc8dff2 (patch) | |
tree | f3c5effdd3b46743539d6efcbef65aaedc0b62a6 /src/html | |
parent | 5be29f675fc27974ff256cb2094ccd0854e19b07 (diff) | |
download | chawan-683cf2ee3ce2fbf6304839d3b68236228fc8dff2.tar.gz |
htmltokenizer: fix newline handling with insufficient buffer length
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/htmltokenizer.nim | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/html/htmltokenizer.nim b/src/html/htmltokenizer.nim index a8961e2f..d09f54dd 100644 --- a/src/html/htmltokenizer.nim +++ b/src/html/htmltokenizer.nim @@ -128,7 +128,7 @@ proc newTokenizer*(s: string): Tokenizer = func atEof(t: Tokenizer): bool = t.eof_i != -1 and t.sbuf_i >= t.eof_i -proc consume(t: var Tokenizer): Rune = +proc checkBufLen(t: var Tokenizer) = if t.sbuf_i >= min(bufLen - copyBufLen, t.sbuf.len): for i in t.sbuf_i ..< t.sbuf.len: t.sbuf[i - t.sbuf_i] = t.sbuf[i] @@ -136,10 +136,14 @@ proc consume(t: var Tokenizer): Rune = t.sbuf_i = 0 if t.sbuf.len < bufLen: t.readn() + +proc consume(t: var Tokenizer): Rune = + t.checkBufLen() ## Normalize newlines (\r\n -> \n, single \r -> \n) if t.sbuf[t.sbuf_i] == Rune('\r'): inc t.sbuf_i - if t.sbuf[t.sbuf_i] != Rune('\n'): + t.checkBufLen() + if t.atEof or t.sbuf[t.sbuf_i] != Rune('\n'): # \r result = Rune('\n') return |