From 179991fc1a280b030bb186dae7d9caa455c641ae Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 24 Nov 2026 19:51:49 +0100 Subject: [PATCH] fix: saving a router model strips the trailing space from a pattern (#34957) A pattern like "```|def |function " (the example in the docs) lost its trailing space when the router model was saved, from the dialog or through the API. "function" without a space after it then matched as well, so a message about "functionality" went to the model meant for code. Patterns are now saved exactly as typed, and a pattern saved before this needs its space typed again. Conditions saved through the API now keep their spaces as sent too. Fixes #34898 --- backend/open_webui/routers/configs.py | 2 +- .../components/admin/Settings/Models/RouterModelModal.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/routers/configs.py b/backend/open_webui/routers/configs.py index ad583402b4..46689dabc7 100644 --- a/backend/open_webui/routers/configs.py +++ b/backend/open_webui/routers/configs.py @@ -733,7 +733,7 @@ class RouterModelRoute(BaseModel): @field_validator('condition', 'pattern', mode='before') @classmethod def normalize_empty(cls, value): - return (value or '').strip() or None + return value if (value or '').strip() else None @model_validator(mode='after') def validate_match(self): diff --git a/src/lib/components/admin/Settings/Models/RouterModelModal.svelte b/src/lib/components/admin/Settings/Models/RouterModelModal.svelte index ef64fab8c9..6d447713af 100644 --- a/src/lib/components/admin/Settings/Models/RouterModelModal.svelte +++ b/src/lib/components/admin/Settings/Models/RouterModelModal.svelte @@ -128,7 +128,7 @@ const routes = [ ...patternRoutes .filter((route) => route.model_id && route.pattern.trim()) - .map((route) => ({ model_id: route.model_id, pattern: route.pattern.trim() })), + .map((route) => ({ model_id: route.model_id, pattern: route.pattern })), ...conditions.map((route) => ({ model_id: route.model_id, condition: route.condition.trim()