forked from joejulian/gio
text: fix EOF detection at newline boundaries
This commit tests and fixes some edge cases that threw off rune accounting when a newline character was the final rune in the input *and* the text was being truncated. I imagine they were never previously reported because it's rare to try to truncate such text. Thanks to Dominik Honnef for the report and reproducer. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
+4
-1
@@ -316,7 +316,9 @@ func (l *Shaper) layoutText(params Parameters, txt io.Reader, str string) {
|
||||
if !done {
|
||||
_, re := l.reader.ReadByte()
|
||||
done = re != nil
|
||||
_ = l.reader.UnreadByte()
|
||||
if !done {
|
||||
_ = l.reader.UnreadByte()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
idx := strings.IndexByte(str, '\n')
|
||||
@@ -325,6 +327,7 @@ func (l *Shaper) layoutText(params Parameters, txt io.Reader, str string) {
|
||||
endByte = len(str)
|
||||
} else {
|
||||
endByte = idx + 1
|
||||
done = endByte == len(str)
|
||||
}
|
||||
}
|
||||
if len(str[:endByte]) > 0 || (len(l.paragraph) > 0 || len(l.txt.lines) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user