|
5 | 5 | //! This is an internal implementation detail used by the Android backend to inject |
6 | 6 | //! initialization scripts when `addDocumentStartJavaScript` is not supported. |
7 | 7 |
|
8 | | -use base64::{engine::general_purpose, Engine}; |
| 8 | +use base64::{prelude::BASE64_STANDARD, Engine}; |
9 | 9 | use dom_query::Document; |
10 | 10 | use http::{ |
11 | 11 | header::{HeaderValue, CONTENT_SECURITY_POLICY, CONTENT_TYPE}, |
@@ -79,7 +79,7 @@ fn hash_script(script: &str) -> String { |
79 | 79 | let mut hasher = Sha256::new(); |
80 | 80 | hasher.update(script); |
81 | 81 | let hash = hasher.finalize(); |
82 | | - format!("'sha256-{}'", general_purpose::STANDARD.encode(hash)) |
| 82 | + format!("'sha256-{}'", BASE64_STANDARD.encode(hash)) |
83 | 83 | } |
84 | 84 |
|
85 | 85 | #[cfg(test)] |
@@ -123,16 +123,17 @@ mod tests { |
123 | 123 | fn test_inject_multiple_scripts() { |
124 | 124 | let body = "<html><head></head><body>Content</body></html>"; |
125 | 125 | 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(), |
129 | 130 | ]; |
130 | 131 |
|
131 | 132 | let result = run(body, "text/html", scripts); |
132 | 133 |
|
133 | 134 | assert_eq!( |
134 | 135 | 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>" |
136 | 137 | ); |
137 | 138 | } |
138 | 139 |
|
|
0 commit comments