Skip to content

Commit 0fae11c

Browse files
author
Fix Bot
committed
fix: preserve * _ ` inside quoted strings in _normalizeCommandText
The previous normalization stripped markdown chars (* _ `) from the entire AI response text, including the content inside Termux("...") arguments. This corrupted shell commands that use: - * for glob patterns (e.g. ls /data/*.apk) - _ in paths/variables (e.g. airodump-ng, $_VAR) - ` for subshell (e.g. echo `cmd`) Fix: tokenize the text into quoted / unquoted segments and only strip markdown chars from unquoted segments. Quoted segments (both single and double quoted, with backslash-escape awareness) are preserved verbatim. Fixes broken command detection for complex Termux commands like: Termux("su -c 'iw dev && grep -E \"type|channel\"'")
1 parent 4b1e0dc commit 0fae11c

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

index.html

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,10 +3609,37 @@
36093609
*/
36103610
function _normalizeCommandText(text) {
36113611
// Strip markdown bold/italic/code markers (* _ `) that AIs sometimes wrap
3612-
// around commands (e.g. **completed()** or __home()__). These characters
3613-
// are never part of any command syntax, so removing them is safe and makes
3614-
// every command robust against markdown formatting.
3615-
return text.replace(/[*_`]/g, '').replace(/\s+/g, ' ').replace(/\r\n|\r/g, '\n').trim();
3612+
// around commands (e.g. **completed()** or __home()__), but ONLY outside of
3613+
// quoted strings. Inside quoted strings these characters are valid shell
3614+
// syntax (glob *, variable _, backtick subshell) and must be preserved.
3615+
text = text.replace(/\r\n|\r/g, '\n');
3616+
3617+
// Tokenise into quoted / unquoted segments, then strip markdown chars only
3618+
// from the unquoted segments and collapse whitespace there too.
3619+
const parts = [];
3620+
let i = 0;
3621+
while (i < text.length) {
3622+
const ch = text[i];
3623+
if (ch === '"' || ch === "'") {
3624+
// Quoted segment – scan to matching closing quote, honouring backslash escapes.
3625+
let j = i + 1;
3626+
while (j < text.length) {
3627+
if (text[j] === '\\') { j += 2; continue; }
3628+
if (text[j] === ch) { j++; break; }
3629+
j++;
3630+
}
3631+
parts.push(text.slice(i, j)); // preserve verbatim
3632+
i = j;
3633+
} else {
3634+
// Unquoted segment – scan to next quote.
3635+
let j = i;
3636+
while (j < text.length && text[j] !== '"' && text[j] !== "'") j++;
3637+
parts.push(text.slice(i, j).replace(/[*_`]/g, '').replace(/\s+/g, ' '));
3638+
i = j;
3639+
}
3640+
}
3641+
3642+
return parts.join('').trim();
36163643
}
36173644

36183645
/* ── CommandPatternConfig (remote regex overrides for EXISTING command types) ── */

0 commit comments

Comments
 (0)