aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-07-13 21:49:04 -0600
committerbors-servo <metajack+bors@gmail.com>2015-07-13 21:49:04 -0600
commitdb90d484edd3a3c1b44030a76d8d011e2ca048fc (patch)
tree4999ce197c1ca216eb9cb6014bddff7f6886c9cb /components/script
parent03232aca3e1b4e66b939ca0a7e42c980f452fb8e (diff)
parenta5b6cb6b433516068a8810f8eb9da894c2c3d8e9 (diff)
downloadservo-db90d484edd3a3c1b44030a76d8d011e2ca048fc.tar.gz
servo-db90d484edd3a3c1b44030a76d8d011e2ca048fc.zip
Auto merge of #6614 - servo:replace-surrogates, r=Ms2ger
Add a `-Z replace-surrogates` command-line option. See #6564. r? @Ms2ger <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6614) <!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/bindings/conversions.rs28
-rw-r--r--components/script/lib.rs2
2 files changed, 28 insertions, 2 deletions
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 9967b6cf9b7..9f6ed02a289 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -352,10 +352,34 @@ pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), s, &mut length)
};
assert!(!chars.is_null());
- let char_vec = unsafe {
+ let potentially_ill_formed_utf16 = unsafe {
slice::from_raw_parts(chars as *const u16, length as usize)
};
- String::from_utf16(char_vec).unwrap()
+ let mut s = String::with_capacity(length as usize);
+ for item in ::rustc_unicode::str::utf16_items(potentially_ill_formed_utf16) {
+ use ::rustc_unicode::str::Utf16Item::*;
+ match item {
+ ScalarValue(c) => s.push(c),
+ LoneSurrogate(_) => {
+ // FIXME: Add more info like document URL in the message?
+ macro_rules! message {
+ () => {
+ "Found an unpaired surrogate in a DOM string. \
+ If you see this in real web content, \
+ please comment on https://github.com/servo/servo/issues/6564"
+ }
+ }
+ if ::util::opts::get().replace_surrogates {
+ error!(message!());
+ s.push('\u{FFFD}');
+ } else {
+ panic!(concat!(message!(), " Use `-Z replace-surrogates` \
+ on the command line to make this non-fatal."));
+ }
+ }
+ }
+ }
+ s
}
}
diff --git a/components/script/lib.rs b/components/script/lib.rs
index 6b3f5ce8c8f..15a1c4c5db5 100644
--- a/components/script/lib.rs
+++ b/components/script/lib.rs
@@ -21,6 +21,7 @@
#![feature(rc_unique)]
#![feature(slice_chars)]
#![feature(str_utf16)]
+#![feature(unicode)]
#![feature(vec_push_all)]
#![deny(unsafe_code)]
@@ -49,6 +50,7 @@ extern crate msg;
extern crate net_traits;
extern crate num;
extern crate rustc_serialize;
+extern crate rustc_unicode;
extern crate time;
extern crate canvas;
extern crate canvas_traits;