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
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-24 22:51:49 +04:00
1 parent bb98273f9e
commit 179991fc1a
2 files changed
+2 -2

No files matched your search

+1 -1
View File
@@ -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):
@@ -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()