diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 00e3f130..5078585b 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -22,7 +22,7 @@ }, { "ImportPath": "github.com/yudai/utf8reader", - "Rev": "543610cf49fc1279921d6ef1b7f7773ebece14f8" + "Rev": "0ccad3e5e2d8dc2493179319c4c8d1172f583ea4" } ] } diff --git a/Godeps/_workspace/src/github.com/yudai/utf8reader/LICENSE b/Godeps/_workspace/src/github.com/yudai/utf8reader/LICENSE new file mode 100644 index 00000000..ab7d2e0f --- /dev/null +++ b/Godeps/_workspace/src/github.com/yudai/utf8reader/LICENSE @@ -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. diff --git a/Godeps/_workspace/src/github.com/yudai/utf8reader/README.md b/Godeps/_workspace/src/github.com/yudai/utf8reader/README.md index 64e419ab..8cd2a26b 100644 --- a/Godeps/_workspace/src/github.com/yudai/utf8reader/README.md +++ b/Godeps/_workspace/src/github.com/yudai/utf8reader/README.md @@ -63,3 +63,7 @@ Of course, bytes left behind will be used to fill up the buffer on next `Read()` ## 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. + +## License + +The MIT License diff --git a/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader.go b/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader.go index 5d2057e5..745edbce 100644 --- a/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader.go +++ b/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader.go @@ -43,7 +43,7 @@ func (r *UTF8Reader) Read(p []byte) (n int, err error) { } leftOver := 0 - for ; leftOver < utf8.UTFMax; leftOver++ { + for ; leftOver < utf8.UTFMax && size-leftOver > 0; leftOver++ { rune, _ := utf8.DecodeLastRune(p[:size-leftOver]) if rune != utf8.RuneError { break diff --git a/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader_test.go b/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader_test.go index 2e0e01bb..c5cfa20d 100644 --- a/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader_test.go +++ b/Godeps/_workspace/src/github.com/yudai/utf8reader/utf8reader_test.go @@ -77,3 +77,21 @@ func TestReadWithSmallBuffer(t *testing.T) { 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") + } +}