Skip to content

fix: decode XML entities in wiki structures salvaged by regex - #631

Merged
sng-asyncfunc merged 1 commit into
AsyncFuncAI:mainfrom
lbarrosby:fix-structure-regex-unescape
Nov 13, 2026
Merged

sng-asyncfunc merged 1 commit into
AsyncFuncAI:mainfrom
lbarrosby:fix-structure-regex-unescape

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

parse_wiki_structure (api/services/wiki/structure.py) escapes every bare & to & before parsing, so that one & does not break strict XML. When strict parsing fails anyway, most often on a response cut off at the output-token limit (the salvage path), the regex fallbacks return the element text as it is in the source. Nothing decodes it, so:

  • a page or section titled Build & Test is shown as Build & Test in the sidebar and page header,
  • entities the model wrote itself (<core>, &) stay encoded in the wiki title, description, page titles and file paths.

The strict path does not have this problem because ElementTree decodes entities. The texts captured by _pages_via_regex, _sections_via_regex and _first_group now go through html.unescape after strip(). Two small helpers (_text, _texts) replace the repeated strip-and-filter comprehensions.

Test: test_parse_truncated_response_decodes_entities feeds a truncated structure with a bare & in the wiki, page and section titles and &/</> in the description and a file path. On main it fails with 'Build & Release Wiki' == 'Build & Release Wiki', and with this change it passes. pytest tests/backend passes (61 tests).

parse_wiki_structure escapes every bare '&' to '&' before parsing.
When strict parsing fails, as it does for a truncated response, the
regex fallback returned the raw element text, so a title like
"Build & Test" showed up as "Build & Test", and entities the model
wrote itself (<, >) were never decoded. Decode the texts the
fallback captures, as ElementTree does on the strict path.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@sng-asyncfunc
sng-asyncfunc merged commit 72f7d7f into AsyncFuncAI:main Nov 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants