diff options
| author | Edward Barnard | 2016-09-06 21:14:10 +0100 |
|---|---|---|
| committer | Edward Barnard | 2016-09-06 21:14:10 +0100 |
| commit | effd194f6e81a8f0cb00e03914764353f67f8b32 (patch) | |
| tree | 7c0d647649560c0c0ec6cbd0bc8d93d742b5fcff | |
| parent | 8b008d1766efff551694d32501525633a0045b06 (diff) | |
| download | rust-plist-effd194f6e81a8f0cb00e03914764353f67f8b32.tar.bz2 | |
Correctly read the length of UTF16 strings
Closes #12
| -rw-r--r-- | src/binary/reader.rs | 14 | ||||
| -rw-r--r-- | tests/data/utf16_bplist.plist | bin | 3301 -> 1378 bytes |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/binary/reader.rs b/src/binary/reader.rs index ffb0caf..5b26777 100644 --- a/src/binary/reader.rs +++ b/src/binary/reader.rs @@ -216,8 +216,9 @@ impl<R: Read + Seek> EventReader<R> { } (0x6, n) => { // UTF-16 string - // n is the length of code units (16 bits), not bytes. - let len = try!(self.read_object_len(n * 2)); + // n is the length of 16 bit code units + // len is the number of bytes + let len = try!(self.read_object_len(n)) * 2; let raw = try!(self.read_data(len)); let mut cursor = Cursor::new(raw); @@ -341,7 +342,12 @@ mod tests { let reader = File::open(&Path::new("./tests/data/utf16_bplist.plist")).unwrap(); let streaming_parser = EventReader::new(reader); - let events: Vec<PlistEvent> = streaming_parser.map(|e| e.unwrap()).collect(); - assert_eq!(events[38], StringValue("\u{2605} or better".to_owned())); + let mut events: Vec<PlistEvent> = streaming_parser.map(|e| e.unwrap()).collect(); + + assert_eq!(events[2], StringValue("\u{2605} or better".to_owned())); + + let poem = if let StringValue(ref mut poem) = events[4] { poem } else { panic!("not a string") }; + assert_eq!(poem.len(), 643); + assert_eq!(poem.pop().unwrap(), '\u{2605}'); } } diff --git a/tests/data/utf16_bplist.plist b/tests/data/utf16_bplist.plist Binary files differindex b1a6856..a50477c 100644 --- a/tests/data/utf16_bplist.plist +++ b/tests/data/utf16_bplist.plist |
