Add sanitizeChatGPTModelData function and update usage in options

This commit is contained in:
Mic 2025-04-27 22:20:00 +02:00
parent 3e6603bd6a
commit 2e22cea996
2 changed files with 6 additions and 2 deletions

View file

@ -415,6 +415,10 @@ export function validateChatGPTWebCustomData(data) {
return data.startsWith('/g/') || data == ''; return data.startsWith('/g/') || data == '';
} }
export function sanitizeChatGPTModelData(input) {
return encodeURIComponent(input).toLowerCase()
}
export function sanitizeChatGPTWebCustomData(input) { export function sanitizeChatGPTWebCustomData(input) {
// Removes all characters that are not letters, numbers, dashes, or slashes // Removes all characters that are not letters, numbers, dashes, or slashes
return input.replace(/[^\p{L}\p{N}\/-]+/gu, ''); return input.replace(/[^\p{L}\p{N}\/-]+/gu, '');

View file

@ -22,7 +22,7 @@ import { OpenAI } from '../js/api/openai.js';
import { Ollama } from '../js/api/ollama.js'; import { Ollama } from '../js/api/ollama.js';
import { OpenAIComp } from '../js/api/openai_comp.js' import { OpenAIComp } from '../js/api/openai_comp.js'
import { GoogleGemini } from '../js/api/google_gemini.js'; import { GoogleGemini } from '../js/api/google_gemini.js';
import { checkSparksPresence, isThunderbird128OrGreater, openTab, validateChatGPTWebCustomData, sanitizeChatGPTWebCustomData } from '../js/mzta-utils.js'; import { checkSparksPresence, isThunderbird128OrGreater, openTab, validateChatGPTWebCustomData, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData } from '../js/mzta-utils.js';
let taLog = new taLogger("mzta-options",true); let taLog = new taLogger("mzta-options",true);
let _isThunderbird128OrGreater = true; let _isThunderbird128OrGreater = true;
@ -689,7 +689,7 @@ document.addEventListener('DOMContentLoaded', async () => {
let webproject_set = false; let webproject_set = false;
if((prefs_mod.chatgpt_web_model != '') && (prefs_mod.chatgpt_web_model != undefined)){ if((prefs_mod.chatgpt_web_model != '') && (prefs_mod.chatgpt_web_model != undefined)){
model_opt = '?model=' + encodeURIComponent(prefs_mod.chatgpt_web_model).toLowerCase(); model_opt = '?model=' + sanitizeChatGPTModelData(prefs_mod.chatgpt_web_model);
} }
if((prefs_mod.chatgpt_web_project != '') && (prefs_mod.chatgpt_web_project != undefined)){ if((prefs_mod.chatgpt_web_project != '') && (prefs_mod.chatgpt_web_project != undefined)){
base_url += sanitizeChatGPTWebCustomData(prefs_mod.chatgpt_web_project); base_url += sanitizeChatGPTWebCustomData(prefs_mod.chatgpt_web_project);