Skip to content

ixml parser: read a CDATA section - #1229

Merged
larshp merged 1 commit into
open-abap:mainfrom
abap2UI5:claude/nifty-meitner-ema3y8-cdata
Sep 15, 2026
Merged

larshp merged 1 commit into
open-abap:mainfrom
abap2UI5:claude/nifty-meitner-ema3y8-cdata

Conversation

@oblomov-dev

Copy link
Copy Markdown
Contributor

What is wrong

A document that carries a CDATA section does not parse. <![CDATA[ falls into
the branch for a start or close tag, where the tag regex does not match it:

ELSEIF lv_xml CP '<*'.
* start or close tag
  FIND FIRST OCCURRENCE OF REGEX lc_regex_tag IN lv_xml RESULTS ls_match.
  ASSERT ls_match-offset = 0.

so the parse ends in ASSERTION_FAILED. That is an assertion, not an
exception — no CATCH cx_root around the parse absorbs it, the caller has no
way to handle the document at all:

parse( |<root><item><![CDATA[a<b&c]]></item></root>| ).
" ASSERTION_FAILED

A section is the one form in which < and & may stand in a document as
text, so it is what a producer reaches for whenever a value carries markup —
an embedded XML or HTML fragment, a snippet of source code, a serialized
payload inside a field.

The change

The loop takes a section ahead of the tag branch: everything between
<![CDATA[ and ]]> becomes the value of a #text node, exactly as it
stands. Nothing in it is unescaped — that is what the section is for, an
&lt; inside one is the four characters &lt; and not <.

ELSEIF lv_xml CP '<![CDATA[*'.
  FIND FIRST OCCURRENCE OF ']]>' IN lv_xml MATCH OFFSET lv_offset.
  ASSERT sy-subrc = 0.
  lv_length = lv_offset - c_cdata_length.
  lv_value = lv_xml+c_cdata_length.
  lv_value = lv_value(lv_length).
  ...

A document without a section is not touched — the new branch is only reached
by the literal <![CDATA[.

Tests

  • parse_cdata<![CDATA[a<b&c]]> reads as a<b&c
  • parse_cdata_not_unescaped<![CDATA[a&lt;b]]> stays a&lt;b
  • parse_cdata_newline — a line break inside a section survives
  • parse_cdata_empty<![CDATA[]]> is an empty value, not a failure

npm test is green: abaplint: 0 issue(s) found, 735 file(s) analyzed, and
the full unit run passes.

Not in this PR

A comment fails the same way and for the same reason — <!-- c --> reaches
the tag branch and ends in ASSERTION_FAILED (measured on this branch). It
wants its own change: a comment is skipped rather than turned into a node,
and it may sit before the root element, where a section may not.

@larshp

larshp commented Sep 15, 2026

Copy link
Copy Markdown
Member

conflicts

@oblomov-dev
oblomov-dev force-pushed the claude/nifty-meitner-ema3y8-cdata branch from 702ee68 to 500cbb6 Compare September 15, 2026 11:36
@larshp

larshp commented Sep 15, 2026

Copy link
Copy Markdown
Member

conflicts

A document that carries one did not parse: "<![CDATA[" enters the branch for
a start or close tag, the tag regex does not match it and the parse dies in
`ASSERT ls_match-offset = 0` - an assertion, so no CATCH cx_root absorbs it,
and a section is the one form in which markup characters may stand in a
document as text.

The loop now takes a section ahead of the tag branch: everything up to "]]>"
becomes the value of a #text node, as it stands. Nothing in it is unescaped,
which is what the section is for.

Tests: markup characters inside a section, an entity that stays text, a line
break, and an empty section.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKSWLpid4QLV6XWAoPixbb
@oblomov-dev
oblomov-dev force-pushed the claude/nifty-meitner-ema3y8-cdata branch from 500cbb6 to b4a1da3 Compare September 15, 2026 11:52
@larshp
larshp merged commit b9233bb into open-abap:main Sep 15, 2026
7 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.

3 participants