You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.warn("[TAURI] Couldn't find callback id {fn} in window. This happens when the app is reloaded while Rust is running an asynchronous operation.")
111
-
}}
112
-
"#,
113
-
fn = function_name.0,
114
-
arg = $arg
115
-
)
116
-
}
117
-
}
118
-
119
-
// get a raw &str representation of a serialized json value.
120
-
let string = serde_json::to_string(arg)?;
121
-
let raw = RawValue::from_string(string)?;
122
-
123
-
// from here we know json.len() > 1 because an empty string is not a valid json value.
124
-
let json = raw.get();
125
-
let first = json.as_bytes()[0];
126
-
127
-
#[cfg(debug_assertions)]
128
-
if first == b'"'{
129
-
debug_assert!(
130
-
json.len() < MAX_JSON_STR_LEN,
131
-
"passing a callback string larger than the max JavaScript literal string size"
206
+
serialize_js_with(arg, |arg| {
207
+
format!(
208
+
r#"
209
+
if (window["_{fn}"]) {{
210
+
window["_{fn}"]({arg})
211
+
}} else {{
212
+
console.warn("[TAURI] Couldn't find callback id {fn} in window. This happens when the app is reloaded while Rust is running an asynchronous operation.")
213
+
}}"#,
214
+
fn = function_name.0,
215
+
arg = arg
132
216
)
133
-
}
134
-
135
-
// only use JSON.parse('{arg}') for arrays and objects less than the limit
136
-
// smaller literals do not benefit from being parsed from json
137
-
Ok(
138
-
if json.len() > MIN_JSON_PARSE_LEN && (first == b'{' || first == b'['){
139
-
let escaped = escape_json_parse(&raw);
140
-
if escaped.len() < MAX_JSON_STR_LEN{
141
-
format_callback!(escaped)
142
-
}else{
143
-
format_callback!(json)
144
-
}
145
-
}else{
146
-
format_callback!(json)
147
-
},
148
-
)
217
+
})
149
218
}
150
219
151
220
/// Formats a Result type to its Promise response.
r#"{"test":"don\\🚀🐱👤\\'t forget to escape me!🚀🐱👤","te🚀🐱👤st2":"don't forget to escape me!","test3":"\\🚀🐱👤\\\\'''\\\\🚀🐱👤\\\\🚀🐱👤\\'''''"}"#.into()
201
297
).unwrap();
@@ -207,7 +303,7 @@ mod test {
207
303
.replace('\\',"\\\\")
208
304
.replace('\'',"\\'")
209
305
);
210
-
let escape_single_quoted_json_test = escape_json_parse(&dangerous_json);
306
+
let escape_single_quoted_json_test = escape(&dangerous_json);
211
307
212
308
let result = r#"JSON.parse('{"test":"don\\\\🚀🐱👤\\\\\'t forget to escape me!🚀🐱👤","te🚀🐱👤st2":"don\'t forget to escape me!","test3":"\\\\🚀🐱👤\\\\\\\\\'\'\'\\\\\\\\🚀🐱👤\\\\\\\\🚀🐱👤\\\\\'\'\'\'\'"}')"#;
0 commit comments