Skip to content

Commit 35b1b62

Browse files
committed
std: decode even numbered non-BMP planes in the UTF-16 decoder.
Fixes #12318.
1 parent a96cea4 commit 35b1b62

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/libstd/str.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ impl<'a> Iterator<UTF16Item> for UTF16Items<'a> {
881881
}
882882

883883
// all ok, so lets decode it.
884-
let c = (u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32 | 0x1_0000;
884+
let c = ((u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
885885
Some(ScalarValue(unsafe {cast::transmute(c)}))
886886
}
887887
}
@@ -3824,7 +3824,10 @@ mod tests {
38243824
0xdc9c_u16, 0xd801_u16, 0xdc92_u16, 0xd801_u16,
38253825
0xdc96_u16, 0xd801_u16, 0xdc86_u16, 0x0020_u16,
38263826
0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16,
3827-
0x000a_u16 ]) ];
3827+
0x000a_u16 ]),
3828+
// Issue #12318, even-numbered non-BMP planes
3829+
(~"\U00020000",
3830+
~[0xD840, 0xDC00])];
38283831
38293832
for p in pairs.iter() {
38303833
let (s, u) = (*p).clone();

0 commit comments

Comments
 (0)