The keyDown/keyUp paths interpolated `key`/`code` into the generated KeyboardEvent snippet with single-quote escaping only. Chrome sends `key: "\"` (U+005C) for the backslash key, which became `key:'\'` — the backslash escaped the closing quote, ran the string literal on, and made the whole page.evaluate a syntax error, so the keydown was silently dropped. Any key/code carrying a backslash broke dispatch. Escape backslash before single-quote (backslash first, so the quote-escape backslashes are not themselves doubled), matching the sibling text path in the same function. Adds a regression test asserting the backslash key arrives at a keydown listener alongside an ordinary key.
This commit is contained in:
1 parent
b2e4bb49a7
commit
57949a0efc
2 files changed
+112
-4
No files matched your search
@@ -151,8 +151,12 @@ pub async fn handle(
|
||||
var evt = globalThis.__obscura_markTrusted(new KeyboardEvent('keydown', {{bubbles:true,cancelable:true,key:'{key}',code:'{code}'}}));\
|
||||
target.dispatchEvent(evt);\
|
||||
}})()",
|
||||
key = key.replace('\'', "\\'"),
|
||||
code = code.replace('\'', "\\'"),
|
||||
// Escape backslash BEFORE single-quote (as the text
|
||||
// path below does) so a key like "\" — Chrome's
|
||||
// backslash key — doesn't escape the closing quote
|
||||
// and produce a syntax error that drops the event.
|
||||
key = key.replace('\\', "\\\\").replace('\'', "\\'"),
|
||||
code = code.replace('\\', "\\\\").replace('\'', "\\'"),
|
||||
);
|
||||
page.evaluate(&js);
|
||||
|
||||
@@ -194,8 +198,8 @@ pub async fn handle(
|
||||
var evt = globalThis.__obscura_markTrusted(new KeyboardEvent('keyup', {{bubbles:true,key:'{key}',code:'{code}'}}));\
|
||||
target.dispatchEvent(evt);\
|
||||
}})()",
|
||||
key = key.replace('\'', "\\'"),
|
||||
code = code.replace('\'', "\\'"),
|
||||
key = key.replace('\\', "\\\\").replace('\'', "\\'"),
|
||||
code = code.replace('\\', "\\\\").replace('\'', "\\'"),
|
||||
);
|
||||
page.evaluate(&js);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user