about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-02-17 00:57:16 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2014-02-17 23:53:49 +1100
commit35b1b62ddfc31c2e52b65c2f908c0fcbc6465de5 (patch)
tree3a496c0ca895cefd8a25cc512200908f8fe1c3a7 /src/libstd
parenta96cea4f5a713eb357bde3d395c5453058be88c5 (diff)
downloadrust-35b1b62ddfc31c2e52b65c2f908c0fcbc6465de5.tar.gz
rust-35b1b62ddfc31c2e52b65c2f908c0fcbc6465de5.zip
std: decode even numbered non-BMP planes in the UTF-16 decoder.
Fixes #12318.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/str.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 1ef622002c3..34bcb083134 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -881,7 +881,7 @@ impl<'a> Iterator<UTF16Item> for UTF16Items<'a> {
             }
 
             // all ok, so lets decode it.
-            let c = (u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32 | 0x1_0000;
+            let c = ((u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
             Some(ScalarValue(unsafe {cast::transmute(c)}))
         }
     }
@@ -3824,7 +3824,10 @@ mod tests {
                 0xdc9c_u16, 0xd801_u16, 0xdc92_u16, 0xd801_u16,
                 0xdc96_u16, 0xd801_u16, 0xdc86_u16, 0x0020_u16,
                 0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16,
-                0x000a_u16 ]) ];
+                0x000a_u16 ]),
+             // Issue #12318, even-numbered non-BMP planes
+             (~"\U00020000",
+              ~[0xD840, 0xDC00])];
 
         for p in pairs.iter() {
             let (s, u) = (*p).clone();