Skip to content

Commit 39a2c1c

Browse files
committed
[owl] Fix docparse bad escape via plain string replacement (#910)
* plain string replacement
1 parent 27b06a2 commit 39a2c1c

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

services/api/src/owl/db/gen_executor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,10 @@ async def _load_files(self, message: ChatThreadEntry) -> ChatEntry:
13831383
continue
13841384
for col_name, data in replacements.items():
13851385
_regex = r"(?<!\\)\${" + re.escape(col_name) + r"}"
1386-
c.text = re.sub(_regex, data, c.text)
1386+
# Use lambda to avoid re.sub interpreting backslashes in data as escape sequences
1387+
# 'lambda _, d=data: d' — '_' is the unused match object, d=data binds current
1388+
# loop value as default arg, and the lambda returns d as a literal string.
1389+
c.text = re.sub(_regex, lambda _, d=data: d, c.text)
13871390
c.text = c.text.strip()
13881391
# Re-assemble
13891392
message = ChatEntry.user(content=contents)

services/api/tests/test_types.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,7 @@ def test_id_string_bad(value: str):
7070

7171
def test_string_normalisation():
7272
with pytest.raises(ValidationError, match="Text contains excessive combining marks"):
73-
IdTest(
74-
id=(
75-
"H̵̛͕̞̦̰̜͍̰̥̟͆̏͂̌͑ͅä̷͔̟͓̬̯̟͍̭͉͈̮͙̣̯̬͚̞̭̍̀̾͠"
76-
"m̴̡̧̛̝̯̹̗̹̤̲̺̟̥̈̏͊̔̑̍͆̌̀̚͝͝b̴̢̢̫̝̠̗̼̬̻̮̺̭͔̘͑̆̎̚"
77-
"ư̵̧̡̥̙̭̿̈̀̒̐̊͒͑r̷̡̡̲̼̖͎̫̮̜͇̬͌͘g̷̹͍͎̬͕͓͕̐̃̈́̓̆̚͝"
78-
"ẻ̵̡̼̬̥̹͇̭͔̯̉͛̈́̕r̸̮̖̻̮̣̗͚͖̝̂͌̾̓̀̿̔̀͋̈́͌̈́̋͜"
79-
)
80-
)
73+
IdTest(id=("H̵̛͕̞̦̰̜͍̰̥̟͆̏͂̌͑ͅä̷͔̟͓̬̯̟͍̭͉͈̮͙̣̯̬͚̞̭̍̀̾͠m̴̡̧̛̝̯̹̗̹̤̲̺̟̥̈̏͊̔̑̍͆̌̀̚͝͝b̴̢̢̫̝̠̗̼̬̻̮̺̭͔̘͑̆̎̚ư̵̧̡̥̙̭̿̈̀̒̐̊͒͑r̷̡̡̲̼̖͎̫̮̜͇̬͌͘g̷̹͍͎̬͕͓͕̐̃̈́̓̆̚͝ẻ̵̡̼̬̥̹͇̭͔̯̉͛̈́̕r̸̮̖̻̮̣̗͚͖̝̂͌̾̓̀̿̔̀͋̈́͌̈́̋͜"))
8174

8275
assert IdTest(id="مَرْحَبًا بِكُمْ").id == "مَرْحَبًا بِكُمْ"
8376
assert IdTest(id="สวัสดีครับ คามุย อิอิ").id == "สวัสดีครับ คามุย อิอิ"

services/api/tests/utils/test_lm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ def test_inference_provider_should_prefer_vllm_cloud_over_owned_by() -> None:
1414
router = _make_router()
1515

1616
assert (
17-
router._inference_provider(CloudProvider.VLLM_CLOUD, "openai")
18-
== CloudProvider.VLLM_CLOUD
17+
router._inference_provider(CloudProvider.VLLM_CLOUD, "openai") == CloudProvider.VLLM_CLOUD
1918
)
2019

2120

0 commit comments

Comments
 (0)