Skip to content

ixml parser: skip a DOCTYPE and a processing instruction - #1232

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

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

Conversation

@oblomov-dev

Copy link
Copy Markdown
Contributor

What is wrong

Neither has a branch of its own, so both reach the branch for a start or close
tag, where the tag regex does not match them and the parse dies in
ASSERT ls_match-offset = 0 — an assertion, so no CATCH cx_root absorbs it:

parse( |<!DOCTYPE note SYSTEM "note.dtd"><root><item>A</item></root>| ).
" ASSERTION_FAILED

parse( |<?xml-stylesheet type="text/xsl" href="a.xsl"?><root><item>A</item></root>| ).
" ASSERTION_FAILED

A document that names its DTD, or that carries a stylesheet instruction ahead
of the root element, cannot be read at all — and both stand where they stand
in plenty of files that are otherwise ordinary XML.

The change

The processing instruction needs no new code. The xml declaration was
already skipped by a branch that matches '<?xml *' and then looks for ?>
— and ?> is what every processing instruction ends with, so the pattern
becomes '<?*' and the same three lines serve both:

IF lv_xml CP '<?*'.
  FIND FIRST OCCURRENCE OF '?>' IN lv_xml MATCH OFFSET lv_offset.
  ASSERT lv_offset > 0.
  lv_offset = lv_offset + 2.

The DOCTYPE gets a branch of its own. It ends at its >, except when it
carries an internal subset — there the > of the subset is not the end of the
declaration, and ]> is:

ELSEIF lv_xml CP '<!DOCTYPE*'.
  FIND FIRST OCCURRENCE OF '>' IN lv_xml MATCH OFFSET lv_offset.
  ASSERT sy-subrc = 0.
  FIND FIRST OCCURRENCE OF '[' IN lv_xml MATCH OFFSET lv_subset.
  IF sy-subrc = 0 AND lv_subset < lv_offset.
    FIND FIRST OCCURRENCE OF ']>' IN lv_xml MATCH OFFSET lv_offset.
    ...

Neither carries content of the document, so neither becomes a node — the same
shape as the comment in #1230.

Tests

  • parse_doctype<!DOCTYPE note SYSTEM "note.dtd"> before the root
  • parse_doctype_subset<!DOCTYPE note [<!ELEMENT note (#PCDATA)>]>, where
    the > inside the subset must not end the declaration
  • parse_processing_instruction — a stylesheet instruction before the root
  • parse_instruction_in_element<?target data?> between two elements

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

Both ended in the tag branch, where the tag regex does not match them and the
parse dies in `ASSERT ls_match-offset = 0` - an assertion, so no CATCH cx_root
absorbs it. A document that names its DTD, or that carries a stylesheet
instruction ahead of the root element, could not be read at all.

The xml declaration was already skipped, by a branch that matches '<?xml *'
and then looks for "?>" - which is what every processing instruction ends
with, so the pattern is now '<?*' and the same three lines serve both.

A DOCTYPE gets its own branch: it ends at its ">", or at "]>" when it carries
an internal subset, whose own ">" is not the end of the declaration.

Tests: a DOCTYPE with a system identifier, one with an internal subset, a
stylesheet instruction before the root element, and an instruction between
two elements.

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-doctype-pi branch from c5432f3 to e2e0fc8 Compare September 15, 2026 13:00
@larshp
larshp merged commit 24b4ded 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