serve: only a whole quoted <function=NAME> opener keeps a parameter value open (#4078)

A bare `<function=` in prose or code (no name, or a name not followed by a
parameter or close) counted as a quoted call, so every later </parameter>
was skipped: the call came out as content, or never finished when streaming.
Adds the review's two values to test_quoted_call_values.
This commit is contained in:
Tsury authored and Niko1221 committed 2026-10-28 23:33:10 +01:00
1 parent 77794e3400
commit b72f56e02a
2 files changed
+8 -2

No files matched your search

+6 -2
View File
@@ -748,15 +748,19 @@ _LOOSE_OPEN = re.compile(r"<\s*(?:function\s*[=:]\s*|=\s*)?([A-Za-z0-9_.\-]+)\s*
_LOOSE_PART = re.compile(r"<\s*(?:function[ \t]*[=:]?\s*|=\s*)?[A-Za-z0-9_.\-]*\s*$")
# a quoted call's opener in a value: `<function=NAME>` and its first parameter or close; a bare FUNC_START is text
_QUOTED_OPEN = re.compile(r"<function=[^<>\s]+>\s*(?:<parameter=|</function>)")
def param_end(text: str, final: bool = False, name: str | None = None) -> int:
"""Where a parameter value in `text` ends: the first PARAM_END followed (after whitespace) by the next
PARAM_START or FUNC_END - the same text inside a value (a file that documents the call format, #210) is
part of the value. #4078: a close inside a call the value itself quotes (more FUNC_START than FUNC_END before
part of the value. #4078: a close inside a call the value itself quotes (more _QUOTED_OPEN than FUNC_END before
it), or one followed by the same parameter `name` again, is part of the value too. `text` starts at the value.
-1: none yet; -2: a candidate whose follower has not arrived (streaming; `final` accepts it)."""
at = text.find(PARAM_END)
while at >= 0:
if text.count(FUNC_START, 0, at) <= text.count(FUNC_END, 0, at):
if len(_QUOTED_OPEN.findall(text, 0, at)) <= text.count(FUNC_END, 0, at):
after = text[at + len(PARAM_END):].lstrip()
if after.startswith(PARAM_START):
gt = after.find(">")
+2
View File
@@ -15,6 +15,8 @@ VALUES = {
"quoted call at the end": f"example transcript:\n{QUOTED}",
"heredoc": f"python3 - <<'PY'\nprint('''{QUOTED}''')\nPY",
"repeated parameter": f"head part\n{PARAM_END}\n{PARAM_START}content>\ntail part",
"unclosed opener in prose": f"A call starts with `{FUNC_START}NAME>` and its parameters follow.",
"unclosed opener in code": f'opener = "{FUNC_START}"\n',
}