mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
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 -->
This commit is contained in:
commit
db90d484ed
3 changed files with 37 additions and 2 deletions
|
@ -352,10 +352,34 @@ pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
|
||||||
JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), s, &mut length)
|
JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), s, &mut length)
|
||||||
};
|
};
|
||||||
assert!(!chars.is_null());
|
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)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#![feature(rc_unique)]
|
#![feature(rc_unique)]
|
||||||
#![feature(slice_chars)]
|
#![feature(slice_chars)]
|
||||||
#![feature(str_utf16)]
|
#![feature(str_utf16)]
|
||||||
|
#![feature(unicode)]
|
||||||
#![feature(vec_push_all)]
|
#![feature(vec_push_all)]
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
@ -49,6 +50,7 @@ extern crate msg;
|
||||||
extern crate net_traits;
|
extern crate net_traits;
|
||||||
extern crate num;
|
extern crate num;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
extern crate rustc_unicode;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate canvas;
|
extern crate canvas;
|
||||||
extern crate canvas_traits;
|
extern crate canvas_traits;
|
||||||
|
|
|
@ -69,6 +69,11 @@ pub struct Opts {
|
||||||
pub userscripts: Option<String>,
|
pub userscripts: Option<String>,
|
||||||
|
|
||||||
pub output_file: Option<String>,
|
pub output_file: Option<String>,
|
||||||
|
|
||||||
|
/// Replace unpaires surrogates in DOM strings with U+FFFD.
|
||||||
|
/// See https://github.com/servo/servo/issues/6564
|
||||||
|
pub replace_surrogates: bool,
|
||||||
|
|
||||||
pub headless: bool,
|
pub headless: bool,
|
||||||
pub hard_fail: bool,
|
pub hard_fail: bool,
|
||||||
|
|
||||||
|
@ -187,6 +192,8 @@ pub fn print_debug_usage(app: &str) -> ! {
|
||||||
print_option("disable-share-style-cache",
|
print_option("disable-share-style-cache",
|
||||||
"Disable the style sharing cache.");
|
"Disable the style sharing cache.");
|
||||||
print_option("parallel-display-list-building", "Build display lists in parallel.");
|
print_option("parallel-display-list-building", "Build display lists in parallel.");
|
||||||
|
print_option("replace-surrogates", "Replace unpaires surrogates in DOM strings with U+FFFD. \
|
||||||
|
See https://github.com/servo/servo/issues/6564");
|
||||||
|
|
||||||
println!("");
|
println!("");
|
||||||
|
|
||||||
|
@ -223,6 +230,7 @@ pub fn default_opts() -> Opts {
|
||||||
nossl: false,
|
nossl: false,
|
||||||
userscripts: None,
|
userscripts: None,
|
||||||
output_file: None,
|
output_file: None,
|
||||||
|
replace_surrogates: false,
|
||||||
headless: true,
|
headless: true,
|
||||||
hard_fail: true,
|
hard_fail: true,
|
||||||
bubble_inline_sizes_separately: false,
|
bubble_inline_sizes_separately: false,
|
||||||
|
@ -397,6 +405,7 @@ pub fn from_cmdline_args(args: &[String]) {
|
||||||
nossl: nossl,
|
nossl: nossl,
|
||||||
userscripts: opt_match.opt_default("userscripts", ""),
|
userscripts: opt_match.opt_default("userscripts", ""),
|
||||||
output_file: opt_match.opt_str("o"),
|
output_file: opt_match.opt_str("o"),
|
||||||
|
replace_surrogates: debug_options.contains(&"replace-surrogates"),
|
||||||
headless: opt_match.opt_present("z"),
|
headless: opt_match.opt_present("z"),
|
||||||
hard_fail: opt_match.opt_present("f"),
|
hard_fail: opt_match.opt_present("f"),
|
||||||
bubble_inline_sizes_separately: bubble_inline_sizes_separately,
|
bubble_inline_sizes_separately: bubble_inline_sizes_separately,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue