Skip to content

Escape XML special characters in XSLT transformation enum values - #341

Open
Markus1812 with Copilot wants to merge 34 commits into
mainfrom
copilot/fix-special-characters-escaping
Open

Markus1812 with Copilot wants to merge 34 commits into
mainfrom
copilot/fix-special-characters-escaping

Conversation

Copilot AI commented Nov 21, 2025

Copy link
Copy Markdown

Fix Transformation Generator Special Character Escaping

This PR fixes the issue where the transformation generator does not properly escape special XML characters in enum values.

Progress:

  • Explore the repository structure and understand the codebase
  • Run existing tests to establish baseline
  • Create test case with enum values containing special characters (< and >)
  • Implement XML escaping function for enum values
  • Apply escaping in get_abap_value method
  • Fix escape order to prevent double-escaping
  • Run tests to verify the fix
  • Lint code to ensure no syntax errors
  • Add integration test for struc_with_special_char_enums

Technical Details:

The issue occurs in zcl_aff_writer_xslt.clas.abap where enum values are written to the XSLT transformation without proper XML escaping.

Changes made:

  1. Added escape_xml_chars method to escape special XML characters:

    • &&#38; (escaped first to prevent double-escaping)
    • <&#60;
    • >&#62;
    • "&#34;
    • '&#39;
  2. Modified get_abap_value method to apply escaping to character and numeric text values

  3. Added test case struc_with_special_char_enums to verify the fix works correctly with enum values containing <, >, and &

  4. Added integration test in ltcl_integration_test_ad that tests the round-trip serialization/deserialization of special character enum values

The fix ensures that enum values with special XML characters are properly escaped in the generated XSLT transformation, preventing XML syntax errors. The ampersand is escaped first to avoid double-escaping of the escape sequences themselves.

Original prompt

This section details on the original issue you should resolve

<issue_title>Transformation Generator does not escape special characters</issue_title>
<issue_description>XML cannot handle special characters such as '<' and '>'. The generator does not escape these characters which leads to syntax errors in the generated transformation when having an enum/constant like

begin of co_enum_values
   less_than type c length 1 value '<',
   greater_thean type c length 1 value '>',
end of co_enum_values.

A solution would be to replace < with &#60 and > with &#62 in the generated transformation. </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 21, 2025 15:44
…erator

Co-authored-by: Markus1812 <7271378+Markus1812@users.noreply.github.com>
Co-authored-by: Markus1812 <7271378+Markus1812@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix transformation generator to escape special characters Escape XML special characters in XSLT transformation enum values Nov 21, 2025
Copilot AI requested a review from Markus1812 November 21, 2025 15:49
Comment thread src/zcl_aff_writer_xslt.clas.testclasses.abap Outdated
@Markus1812
Markus1812 requested a review from wurzka December 1, 2025 08:18
@wurzka
wurzka marked this pull request as ready for review December 2, 2025 07:10

@wurzka wurzka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration test missing

validate_output( act_output ).
ENDMETHOD.

METHOD struc_with_special_char_enums.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration test in ltcl_integration_test_ad missing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration test in ltcl_integration_test_ad missing

@copilot

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added integration test struc_with_special_char_enums in ltcl_integration_test_ad that tests round-trip serialization/deserialization for all three special characters (<, >, &). Commit: 5fb3ed0

Co-authored-by: Markus1812 <7271378+Markus1812@users.noreply.github.com>

Copilot AI commented Dec 2, 2025

Copy link
Copy Markdown
Author

Integration test missing

Added integration test struc_with_special_char_enums in ltcl_integration_test_ad that tests round-trip serialization/deserialization for all three special characters (<, >, &). Commit: 5fb3ed0

Comment on lines +822 to +831
METHOD escape_xml_chars.
result = value.
" Ampersand must be replaced first to avoid double-escaping
REPLACE ALL OCCURRENCES OF '&' IN result WITH '&#38;'.
REPLACE ALL OCCURRENCES OF '<' IN result WITH '&#60;'.
REPLACE ALL OCCURRENCES OF '>' IN result WITH '&#62;'.
REPLACE ALL OCCURRENCES OF '"' IN result WITH '&#34;'.
REPLACE ALL OCCURRENCES OF '''' IN result WITH '&#39;'.
ENDMETHOD.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use ABAP's built-in function escape to escape xml?

See https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENESCAPE_FUNCTIONS.html

k4llist0 and others added 8 commits June 30, 2026 14:13
* update npm dependencies

* update

* run another testcase

* update
* Fix download (and unit test)

* fix linter issue
* update npm dependencies

* update
Bumps [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) from 5.4.2 to 5.5.6.
- [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases)
- [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md)
- [Commits](NaturalIntelligence/fast-xml-parser@v5.4.2...v5.5.6)

---
updated-dependencies:
- dependency-name: fast-xml-parser
  dependency-version: 5.5.6
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
dependabot Bot and others added 19 commits July 2, 2026 14:43
Bumps [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) from 5.5.6 to 5.5.7.
- [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases)
- [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md)
- [Commits](NaturalIntelligence/fast-xml-parser@v5.5.6...v5.5.7)

---
updated-dependencies:
- dependency-name: fast-xml-parser
  dependency-version: 5.5.7
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@abaplint/transpiler-cli](https://github.com/abaplint/transpiler) from 2.13.15 to 2.13.21.
- [Changelog](https://github.com/abaplint/transpiler/blob/main/CHANGELOG.md)
- [Commits](https://github.com/abaplint/transpiler/commits)

---
updated-dependencies:
- dependency-name: "@abaplint/transpiler-cli"
  dependency-version: 2.13.21
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@abaplint/runtime](https://github.com/abaplint/transpiler) from 2.13.15 to 2.13.22.
- [Changelog](https://github.com/abaplint/transpiler/blob/main/CHANGELOG.md)
- [Commits](https://github.com/abaplint/transpiler/commits)

---
updated-dependencies:
- dependency-name: "@abaplint/runtime"
  dependency-version: 2.13.21
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@abaplint/cli](https://github.com/abaplint/abaplint) from 2.119.2 to 2.119.14.
- [Release notes](https://github.com/abaplint/abaplint/releases)
- [Commits](https://github.com/abaplint/abaplint/commits)

---
updated-dependencies:
- dependency-name: "@abaplint/cli"
  dependency-version: 2.119.12
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Michael Schneider <micha.schneider@sap.com>
* chore(hyperspace): 🤖 Add PR Bot Configuration

* Update pull_request_bot.json

---------

Co-authored-by: hyperspace-insights[bot] <209611008+hyperspace-insights[bot]@users.noreply.github.com>
Co-authored-by: Albert Mink <albert.mink@sap.com>
* update npm dependencies

* audit fix
Bumps [@abaplint/transpiler-cli](https://github.com/abaplint/transpiler) from 2.13.30 to 2.13.31.
- [Changelog](https://github.com/abaplint/transpiler/blob/main/CHANGELOG.md)
- [Commits](https://github.com/abaplint/transpiler/commits)

---
updated-dependencies:
- dependency-name: "@abaplint/transpiler-cli"
  dependency-version: 2.13.31
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Remove Callback Handling

* Fix lint

* Remove ignore_til_indent_level and fix minors

* Fix minor

* Fix indentations

* Fix lint

* Remove method

* Fix AbapLint

---------

Co-authored-by: Sara Spangenmacher <s.spangenmacher@sap.com>
Co-authored-by: k4llist0 <93997474+k4llist0@users.noreply.github.com>
Co-authored-by: abaplint[bot] <24845621+abaplint[bot]@users.noreply.github.com>
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.

Transformation Generator does not escape special characters

8 participants