Skip to content

fix: escape DESC and LONG-NAME when unparsing - #239

Merged
stanislaw merged 1 commit into
strictdoc-project:mainfrom
Eliot5566:fix/escape-spec-object-attributes
Nov 19, 2026
Merged

stanislaw merged 1 commit into
strictdoc-project:mainfrom
Eliot5566:fix/escape-spec-object-attributes

Conversation

@Eliot5566

Copy link
Copy Markdown
Contributor

Fixes strictdoc-project/strictdoc#3266

lxml unescapes attribute values when it parses a ReqIF file, so DESC and LONG-NAME are stored as plain text (A & B). Most unparse methods escape them again with lxml_escape_for_html, but these did not:

  • SPEC-OBJECT: DESC and LONG-NAME (the case in the issue)
  • SPEC-RELATION: DESC (LONG-NAME used html.escape already)
  • RELATION-GROUP: DESC and LONG-NAME
  • SPEC-HIERARCHY: LONG-NAME
  • DATATYPE-DEFINITION-*: LONG-NAME in three branches and the DESC of enum values

A requirement whose title contains &, < or " was therefore written as XML the parser itself rejects, so a parse/unparse round trip broke the file. All of these now use lxml_escape_for_html, like SPECIFICATION and the other elements.

Tests:

  • New tests/unit/reqif/parsers/test_attribute_escaping.py: SPEC-OBJECT, SPEC-RELATION and RELATION-GROUP go through a parse, unparse, parse round trip with &, <, > and " in DESC/LONG-NAME, and SPEC-HIERARCHY checks the escaped output. All 4 fail on main and pass with the fix.
  • Unit tests: 82 passed. Integration (lit) tests: same result as main (the same 2 tests fail on both in my environment).
  • ruff check and ruff format --check are clean.

I used Claude to help write and test this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3

lxml unescapes attribute values when parsing, but SPEC-OBJECT,
SPEC-RELATION, RELATION-GROUP, SPEC-HIERARCHY and some DATATYPE
elements wrote DESC/LONG-NAME back without escaping. A value containing
&, < or " produced XML that the parser itself rejects. Escape them with
lxml_escape_for_html, as SPECIFICATION and the other elements already do.

Reported in strictdoc-project/strictdoc#3266.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3
@stanislaw
stanislaw merged commit 7fd3dc3 into strictdoc-project:main Nov 19, 2026
6 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.

ReqIFUnparser writes SPEC-OBJECT @DESC/@LONG-NAME unescaped, and its own reader then refuses the output

2 participants