commit 4f13eaf338db535866eac0c1032ccc53cb88b5eb parent 3e56e39ac2a5433d87b059353981c00ccf5ba788 Author: Nicolas Chevobbe <nchevobbe@mozilla.com> Date: Tue, 9 Dec 2025 08:37:08 +0000 Bug 2004579 - [devtools] Compute string index from character length in analyzeInputString. r=devtools-reviewers,bomsy. We were only increasing the index by 1, which wouldn't account for surrogate pairs (e.g. emojis). We need to increase the index by the character length so the string can be manipulated accurately after. Test case is added to cover the fix. Differential Revision: https://phabricator.services.mozilla.com/D275419 Diffstat:
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/devtools/shared/webconsole/analyze-input-string.js b/devtools/shared/webconsole/analyze-input-string.js @@ -88,7 +88,7 @@ exports.analyzeInputString = function (str, timeout = 2500) { }; } - currentIndex += 1; + currentIndex += c.length; let resetLastStatement = false; const isWhitespaceChar = c.trim() === ""; switch (state) { diff --git a/devtools/shared/webconsole/test/xpcshell/test_analyze_input_string.js b/devtools/shared/webconsole/test/xpcshell/test_analyze_input_string.js @@ -203,6 +203,18 @@ add_task(() => { }, }, { + desc: "string literal with surrogate pair character", + input: `"🧑".c`, + expected: { + isElementAccess: false, + isPropertyAccess: true, + expressionBeforePropertyAccess: `"🧑"`, + lastStatement: `"🧑".c`, + mainExpression: `"🧑"`, + matchProp: `c`, + }, + }, + { desc: "optional chaining operator with spaces", input: `test ?. ["propA"] ?. [0] ?. ["propB"] ?. ['to`, expected: { diff --git a/devtools/shared/webconsole/test/xpcshell/test_js_property_provider.js b/devtools/shared/webconsole/test/xpcshell/test_js_property_provider.js @@ -245,6 +245,8 @@ function runChecks(dbgObject, environment, sandbox) { test_has_result(results, "charAt"); results = propertyProvider("`\\\\`."); test_has_result(results, "charAt"); + results = propertyProvider(`"🧑".c`); + test_has_result(results, "codePointAt"); info("Test that suggestions are not given for syntax errors."); results = propertyProvider("'foo\"");