summaryrefslogtreecommitdiff
path: root/source/net
diff options
context:
space:
mode:
authorMichael Christen <Orbiter@users.noreply.github.com>2026-05-23 22:53:50 +0200
committerGitHub <noreply@github.com>2026-05-23 22:53:50 +0200
commitce9c78f5d372e01eb7c8344dcab6b224df1245e4 (patch)
treed3d7eb1f43d65ac06dbd0e27758a97357460446f /source/net
parentf9b0ced1af2e2c4af2904b43a0704b4be8101dbf (diff)
parent749925a92cd815b41c9876b8688357870ed37307 (diff)
Merge pull request #777 from songproducer/fix/system-prompt-js-escape
Fix JS syntax error when system prompt contains single quotes
Diffstat (limited to 'source/net')
-rw-r--r--source/net/yacy/htroot/yacychat.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/source/net/yacy/htroot/yacychat.java b/source/net/yacy/htroot/yacychat.java
index 0037d4f04..74c081dac 100644
--- a/source/net/yacy/htroot/yacychat.java
+++ b/source/net/yacy/htroot/yacychat.java
@@ -29,7 +29,14 @@ public class yacychat {
// system prompt comes from configuration; default is empty
final String systemPrompt = sb.getConfig("ai.system-prompt", net.yacy.http.servlets.RAGProxyServlet.LLM_SYSTEM_PROMPT_DEFAULT);
- prop.put("system_prompt", systemPrompt);
+ // escape for safe embedding in a JS single-quoted string literal
+ final String systemPromptJs = systemPrompt
+ .replace("\\", "\\\\")
+ .replace("'", "\\'")
+ .replace("\r\n", "\\n")
+ .replace("\n", "\\n")
+ .replace("\r", "\\n");
+ prop.put("system_prompt", systemPromptJs);
prop.put("topmenu", sb.getConfigBool("ai.shield.show-chat-link", false) ? (sb.getConfigBool("publicTopmenu", true) ? 1 : 0) : 2);
String promoteChatPageGreeting = env.getConfig("promoteChatPageGreeting", "");