mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-22 12:24:25 +00:00
Update UTF8Reader to fix slice bounds out of range error
This commit is contained in:
parent
5e3796d644
commit
bc109b4f5b
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/yudai/utf8reader",
|
"ImportPath": "github.com/yudai/utf8reader",
|
||||||
"Rev": "543610cf49fc1279921d6ef1b7f7773ebece14f8"
|
"Rev": "0ccad3e5e2d8dc2493179319c4c8d1172f583ea4"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
21
Godeps/_workspace/src/github.com/yudai/utf8reader/LICENSE
generated
vendored
Normal file
21
Godeps/_workspace/src/github.com/yudai/utf8reader/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Iwasaki Yudai
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
4
Godeps/_workspace/src/github.com/yudai/utf8reader/README.md
generated
vendored
4
Godeps/_workspace/src/github.com/yudai/utf8reader/README.md
generated
vendored
@ -63,3 +63,7 @@ Of course, bytes left behind will be used to fill up the buffer on next `Read()`
|
|||||||
## Note
|
## Note
|
||||||
|
|
||||||
UTF8Reader just checks incomplete bytes at the tail of the buffer. Even if the original byte sequence given to UTF8Reader is broken, UTF8Reader reports no errors and just fills up the buffer.
|
UTF8Reader just checks incomplete bytes at the tail of the buffer. Even if the original byte sequence given to UTF8Reader is broken, UTF8Reader reports no errors and just fills up the buffer.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The MIT License
|
||||||
|
2
Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader.go
generated
vendored
2
Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader.go
generated
vendored
@ -43,7 +43,7 @@ func (r *UTF8Reader) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
leftOver := 0
|
leftOver := 0
|
||||||
for ; leftOver < utf8.UTFMax; leftOver++ {
|
for ; leftOver < utf8.UTFMax && size-leftOver > 0; leftOver++ {
|
||||||
rune, _ := utf8.DecodeLastRune(p[:size-leftOver])
|
rune, _ := utf8.DecodeLastRune(p[:size-leftOver])
|
||||||
if rune != utf8.RuneError {
|
if rune != utf8.RuneError {
|
||||||
break
|
break
|
||||||
|
18
Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader_test.go
generated
vendored
18
Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader_test.go
generated
vendored
@ -77,3 +77,21 @@ func TestReadWithSmallBuffer(t *testing.T) {
|
|||||||
t.Errorf("Expected error were not returned")
|
t.Errorf("Expected error were not returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadWithSmallRead(t *testing.T) {
|
||||||
|
input := []byte("いろは")
|
||||||
|
or := bytes.NewBuffer(input[0:2]) // small read
|
||||||
|
r := New(or)
|
||||||
|
buf := make([]byte, 512)
|
||||||
|
|
||||||
|
_, err := r.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error")
|
||||||
|
}
|
||||||
|
|
||||||
|
or.Write(input[2:6])
|
||||||
|
_, err = r.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user