aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_task.rs
diff options
context:
space:
mode:
authorBenjamin Herr <ben@0x539.de>2015-11-06 11:40:39 +0100
committerBenjamin Herr <ben@0x539.de>2015-11-06 18:15:27 +0100
commit4120283e10bfb2fe0e2677909b82f5c1b8b7051c (patch)
tree7413c8da5a586b1ba4a32e366af973f89b3790ab /components/script/script_task.rs
parent8b030c5177444a5274b1c329802ae9d998cf5df9 (diff)
downloadservo-4120283e10bfb2fe0e2677909b82f5c1b8b7051c.tar.gz
servo-4120283e10bfb2fe0e2677909b82f5c1b8b7051c.zip
Append query string + fragment to javascript: url.
When loading a URL whose scheme is javascript, we should do what https://html.spec.whatwg.org/multipage/#javascript-protocol says and append the URL's query and fragment components to the scheme data, as well as percent- and utf-8-decode the whole thing, before evaluating it as javascript.
Diffstat (limited to 'components/script/script_task.rs')
-rw-r--r--components/script/script_task.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index ac67e4a5996..a53d319b6e8 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -1636,10 +1636,32 @@ impl ScriptTask {
let is_javascript = incomplete.url.scheme == "javascript";
let parse_input = if is_javascript {
+ use url::percent_encoding::percent_decode_to;
+
+ // Turn javascript: URL into JS code to eval, according to the steps in
+ // https://html.spec.whatwg.org/multipage/#javascript-protocol
let _ar = JSAutoRequest::new(self.get_cx());
- let evalstr = incomplete.url.non_relative_scheme_data().unwrap();
+ let mut script_source_bytes = Vec::new();
+ // Start with the scheme data of the parsed URL (5.), while percent-decoding (8.)
+ percent_decode_to(incomplete.url.non_relative_scheme_data().unwrap().as_bytes(),
+ &mut script_source_bytes);
+ // Append question mark and query component, if any (6.), while percent-decoding (8.)
+ if let Some(ref query) = incomplete.url.query {
+ script_source_bytes.push(b'?');
+ percent_decode_to(query.as_bytes(), &mut script_source_bytes);
+ }
+ // Append number sign and fragment component if any (7.), while percent-decoding (8.)
+ if let Some(ref fragment) = incomplete.url.fragment {
+ script_source_bytes.push(b'#');
+ percent_decode_to(fragment.as_bytes(), &mut script_source_bytes);
+ }
+
+ // UTF-8 decode (9.)
+ let script_source = String::from_utf8_lossy(&script_source_bytes);
+
+ // Script source is ready to be evaluated (11.)
let mut jsval = RootedValue::new(self.get_cx(), UndefinedValue());
- window.evaluate_js_on_global_with_result(evalstr, jsval.handle_mut());
+ window.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut());
let strval = DOMString::from_jsval(self.get_cx(), jsval.handle(),
StringificationBehavior::Empty);
strval.unwrap_or(DOMString::new())