abap-file-formats-tools
abap-file-formats-tools copied to clipboard
Escape XML special characters in XSLT transformation enum values
Enum values containing XML special characters (<, >, &, ", ') cause syntax errors in generated XSLT transformations.
Changes
-
Added
escape_xml_charsmethod tozcl_aff_writer_xslt- Escapes
&first to prevent double-escaping of subsequent replacements - Maps:
&→&,<→<,>→>,"→",'→'
- Escapes
-
Modified
get_abap_valuemethod to apply escaping for character and numeric text types -
Added test coverage for enum values with special characters
Example
Before this fix, an enum like:
BEGIN OF co_enum_values,
less_than TYPE c LENGTH 1 VALUE '<',
greater_than TYPE c LENGTH 1 VALUE '>',
END OF co_enum_values.
Would generate invalid XSLT:
<tt:value ref="FIELD" map="val('<')=xml('lessThan')"/>
Now generates valid escaped XSLT:
<tt:value ref="FIELD" map="val('<')=xml('lessThan')"/>
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 < and > with > in the generated transformation. </issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes SAP/abap-file-formats-tools#319
💡 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.