Skip to content

Conversation

Copy link

Copilot AI commented Nov 21, 2025

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
@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
Copy link
Contributor

@wurzka wurzka left a comment

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
Contributor

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
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
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>
Copy link
Author

Copilot AI commented Dec 2, 2025

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
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

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

4 participants