Skip to content

Commit 47d9470

Browse files
fix: scripts wrongly escaped by dom_query (#1693)
* test: add an escape test to dom qeury result * Update dom_query to 0.27
1 parent b79e37b commit 47d9470

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

.changes/dom-query-0.26.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changes/dom-query-0.27.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
wry: patch
3+
---
4+
5+
Updated dependency dom_query to 0.27.0, this fixed a bug where initialization scripts were escaped incorrectly on Android

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ jni = "0.21"
201201
ndk = "0.9"
202202
tao-macros = "0.1"
203203
libc = "0.2"
204-
dom_query = { version = "0.26.0", default-features = false }
204+
dom_query = { version = "0.27.0", default-features = false }
205205

206206
[dev-dependencies]
207207
pollster = "0.4.0"
@@ -216,7 +216,7 @@ libloading = "0.8.9"
216216
# For unit testing `inject_initialization_scripts` since we can't do it easily on Android
217217
sha2 = "0.10"
218218
base64 = "0.22"
219-
dom_query = { version = "0.26.0", default-features = false }
219+
dom_query = { version = "0.27.0", default-features = false }
220220

221221
[lints.rust.unexpected_cfgs]
222222
level = "warn"

src/inject_initialization_scripts.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! This is an internal implementation detail used by the Android backend to inject
66
//! initialization scripts when `addDocumentStartJavaScript` is not supported.
77
8-
use base64::{engine::general_purpose, Engine};
8+
use base64::{prelude::BASE64_STANDARD, Engine};
99
use dom_query::Document;
1010
use http::{
1111
header::{HeaderValue, CONTENT_SECURITY_POLICY, CONTENT_TYPE},
@@ -79,7 +79,7 @@ fn hash_script(script: &str) -> String {
7979
let mut hasher = Sha256::new();
8080
hasher.update(script);
8181
let hash = hasher.finalize();
82-
format!("'sha256-{}'", general_purpose::STANDARD.encode(hash))
82+
format!("'sha256-{}'", BASE64_STANDARD.encode(hash))
8383
}
8484

8585
#[cfg(test)]
@@ -123,16 +123,17 @@ mod tests {
123123
fn test_inject_multiple_scripts() {
124124
let body = "<html><head></head><body>Content</body></html>";
125125
let scripts = vec![
126-
"var first = 1;".to_string(),
127-
"var second = 2;".to_string(),
128-
"var third = 3;".to_string(),
126+
"var first = 1;".to_owned(),
127+
"let second = 2;".to_owned(),
128+
"const third = 3;".to_owned(),
129+
"window.test = () => console.log('test');".to_owned(),
129130
];
130131

131132
let result = run(body, "text/html", scripts);
132133

133134
assert_eq!(
134135
result,
135-
"<html><head><script>var first = 1;</script><script>var second = 2;</script><script>var third = 3;</script></head><body>Content</body></html>"
136+
"<html><head><script>var first = 1;</script><script>let second = 2;</script><script>const third = 3;</script><script>window.test = () => console.log('test');</script></head><body>Content</body></html>"
136137
);
137138
}
138139

0 commit comments

Comments
 (0)