Skip to content

# ixml parser: skip a comment - #1230

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

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

Conversation

@oblomov-dev

Copy link
Copy Markdown
Contributor

What is wrong

A document that carries a comment does not parse. <!-- 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 — an assertion, not an exception, so
no CATCH cx_root around the parse absorbs it:

parse( |<root><!-- c --><item>A</item></root>| ).
" ASSERTION_FAILED

A comment sits in a hand-written or tool-generated document as a matter of
course — a header above the root element, a note next to a setting, an element
commented out — and none of those documents can be read at all today.

The change

The loop takes a comment ahead of the tag branch and skips it as a whole, up
to -->:

ELSEIF lv_xml CP '<!--*'.
  FIND FIRST OCCURRENCE OF '-->' IN lv_xml MATCH OFFSET lv_offset.
  ASSERT sy-subrc = 0.
  lv_offset = lv_offset + 3.
  lv_in_element = abap_false.

A comment carries no content, so it becomes no node — and what stands inside
it is text: the tags of a commented-out element are never read as markup. A
document without a comment is not touched, the new branch is only reached by
the literal <!--.

Tests

  • parse_comment — a comment between two elements, the first child of the
    root is still the element
  • parse_comment_before_root — a comment between the prolog and the root
  • parse_comment_with_markup<!-- <item>A</item> --> is text, the
    element that follows is the one that is read
  • parse_comment_only_child — an element whose whole content is a comment has
    no children

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

A document that carries a comment did not parse: "<!--" 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.

The loop now takes a comment ahead of the tag branch and skips it as a whole,
up to "-->". It carries no content, and what stands inside it is text - the
tags of a commented-out element are never read as markup.

Tests: a comment between two elements, one before the root element, one that
contains markup, and one that is everything an element contains.

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-comment branch from 357627d to d3b2e7e Compare September 15, 2026 12:28
@larshp
larshp merged commit feaba9f 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