summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/settings-schema.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/shared/settings-schema.js b/src/shared/settings-schema.js
index fad7a5f..057812d 100644
--- a/src/shared/settings-schema.js
+++ b/src/shared/settings-schema.js
@@ -33,6 +33,7 @@ export function isValidOllamaHost(value) {
}
if (url.protocol !== 'http:') return false;
if (url.hostname !== 'localhost' && url.hostname !== '127.0.0.1') return false;
+ // Only the root path ("http://host/" or "http://host") is allowed.
if (url.pathname !== '/' && url.pathname !== '') return false;
if (url.search !== '' || url.hash !== '') return false;
if (url.username !== '' || url.password !== '') return false;
@@ -45,6 +46,17 @@ export function isValidOllamaHost(value) {
}
/**
+ * Normalize a validated host for storage: strip the trailing slash so
+ * "http://localhost:11434/" and "http://localhost:11434" are stored
+ * identically.
+ * @param {string} host already validated host
+ * @returns {string}
+ */
+export function normalizeOllamaHost(host) {
+ return host.replace(/\/+$/, '') || 'http://localhost';
+}
+
+/**
* @param {*} value
* @returns {boolean}
*/
@@ -189,7 +201,7 @@ export function sanitizeSettings(stored) {
if (isValidOllamaHost(stored.ollamaHost)) {
// Normalize: strip trailing slash.
- result.ollamaHost = stored.ollamaHost.replace(/\/+$/, '') || DEFAULT_OLLAMA_HOST;
+ result.ollamaHost = normalizeOllamaHost(stored.ollamaHost) || DEFAULT_OLLAMA_HOST;
}
if (typeof stored.model === 'string' && stored.model.length <= 256) {