mirror of
https://git.zavage.net/Zavage-Software/search-with-chatgpt-powered-by-openai-extension.git
synced 2026-08-31 22:20:47 -06:00
fix: stop $ sequences in selected text corrupting the prompt
This commit is contained in:
+6
-1
@@ -21,7 +21,12 @@ function applyTemplate(template, query) {
|
||||
}
|
||||
const tpl = typeof template === "string" ? template : "";
|
||||
if (tpl.includes("{query}")) {
|
||||
return tpl.replaceAll("{query}", query);
|
||||
// Replacer function, not a replacement string: String.prototype.replaceAll
|
||||
// gives $&, $`, $', and $$ special meaning in a replacement STRING, and
|
||||
// `query` is arbitrary page-selected text that can contain any of those
|
||||
// (shell one-liners routinely do). The function form disables that
|
||||
// interpretation entirely. Do not "simplify" this back to the string form.
|
||||
return tpl.replaceAll("{query}", () => query);
|
||||
}
|
||||
const trimmed = tpl.trim();
|
||||
return trimmed === "" ? query : `${trimmed} ${query}`;
|
||||
|
||||
Reference in New Issue
Block a user