fix handling of unicode during decode

This commit is contained in:
Ty Overby 2014-10-01 23:41:31 -07:00
parent dd996040e8
commit cc327bcec3
2 changed files with 9 additions and 3 deletions

View File

@ -75,11 +75,11 @@ impl <R: Reader> Decoder<IoError> for DecoderReader<R> {
} }
fn read_str(&mut self) -> Result<String, IoError> { fn read_str(&mut self) -> Result<String, IoError> {
let len = try!(self.read_uint()); let len = try!(self.read_uint());
let mut string = String::new(); let mut vector = Vec::with_capacity(len as uint);
for _ in range(0, len) { for _ in range(0, len) {
string.push_char(try!(self.reader.read_char())); vector.push(try!(self.reader.read_u8()));
} }
Ok(string) Ok(String::from_utf8(vector).unwrap())
} }
fn read_enum<T>(&mut self, _: &str, fn read_enum<T>(&mut self, _: &str,
f: |&mut DecoderReader<R>| -> Result<T, IoError>) -> Result<T, IoError> { f: |&mut DecoderReader<R>| -> Result<T, IoError>) -> Result<T, IoError> {

View File

@ -160,3 +160,9 @@ fn boole(){
the_same(true); the_same(true);
the_same(false); the_same(false);
} }
#[test]
fn unicode() {
the_same("å".to_string());
the_same("aåååååååa".to_string());
}