-
Notifications
You must be signed in to change notification settings - Fork 6
Escape XML special characters in XSLT transformation enum values #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b773d73
4028d4b
0bf3564
2eb30a0
c6576d2
c4c077d
5fb3ed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1297,6 +1297,7 @@ CLASS ltcl_type_writer_xslt_ad DEFINITION FINAL FOR TESTING | |
| structure_with_enums FOR TESTING RAISING cx_static_check, | ||
| structure_with_default_problem FOR TESTING RAISING cx_static_check, | ||
| struc_with_own_enum_values FOR TESTING RAISING cx_static_check, | ||
| struc_with_special_char_enums FOR TESTING RAISING cx_static_check, | ||
| enable_extension FOR TESTING RAISING cx_static_check. | ||
| ENDCLASS. | ||
|
|
||
|
|
@@ -2566,6 +2567,39 @@ CLASS ltcl_type_writer_xslt_ad IMPLEMENTATION. | |
| validate_output( act_output ). | ||
| ENDMETHOD. | ||
|
|
||
| METHOD struc_with_special_char_enums. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Integration test in ltcl_integration_test_ad missing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added integration test |
||
| DATA test_type TYPE zcl_aff_test_types=>struc_with_special_char_enums. | ||
| DATA(act_output) = test_generator->generate_type( test_type ). | ||
| me->exp_transformation = VALUE #( | ||
| ( `<tt:cond>` ) | ||
| ( ` <object>` ) | ||
| ( ` <tt:group>` ) | ||
| ( ` <tt:cond s-check="not-initial(SPECIAL_CHAR_ENUM)" frq="?">` ) | ||
| ( ` <str name="specialCharEnum">` ) | ||
| ( ` <tt:value ref="SPECIAL_CHAR_ENUM" map="` ) | ||
| ( ` val('<')=xml('lessThan'),` ) | ||
| ( ` val('>')=xml('greaterThan'),` ) | ||
| ( ` val('&')=xml('ampersand')"` ) | ||
| ( ` />` ) | ||
| ( ` </str>` ) | ||
| ( ` </tt:cond>` ) | ||
| ( ` <tt:d-cond frq="*">` ) | ||
| ( ` <_ tt:lax="on">` ) | ||
| ( ` <tt:call-method class="CL_AFF_XSLT_CALLBACK_TYPE" name="RAISE_DIFFERENT_TYPE_EXCEPTION" reader="IO_READER">` ) | ||
| ( ` <tt:with-parameter name="MEMBERS" val="'specialCharEnum;'"/>` ) | ||
| ( ` </tt:call-method>` ) | ||
| ( ` <tt:skip/>` ) | ||
| ( ` </_>` ) | ||
| ( ` </tt:d-cond>` ) | ||
| ( ` <tt:d-cond frq="?">` ) | ||
| ( ` <__/>` ) | ||
| ( ` </tt:d-cond>` ) | ||
| ( ` </tt:group>` ) | ||
| ( ` </object>` ) | ||
| ( `</tt:cond>` ) ). | ||
| validate_output( act_output ). | ||
| ENDMETHOD. | ||
|
|
||
| METHOD validate_output. | ||
| DATA exp TYPE string_table. | ||
|
|
||
|
|
@@ -2653,6 +2687,8 @@ RISK LEVEL DANGEROUS. | |
|
|
||
| struc_with_own_enum_values FOR TESTING RAISING cx_static_check, | ||
|
|
||
| struc_with_special_char_enums FOR TESTING RAISING cx_static_check, | ||
|
|
||
| from_abap_to_json | ||
| IMPORTING | ||
| test_type TYPE data | ||
|
|
@@ -3224,6 +3260,40 @@ CLASS ltcl_integration_test_ad IMPLEMENTATION. | |
| act_data = test_type ). | ||
| ENDMETHOD. | ||
|
|
||
| METHOD struc_with_special_char_enums. | ||
| DATA test_type TYPE zcl_aff_test_types=>struc_with_special_char_enums. | ||
| test_type = VALUE #( special_char_enum = '<' ). | ||
| exp_json = VALUE #( | ||
| ( `{` ) | ||
| ( ` "specialCharEnum": "lessThan"` ) | ||
| ( `}` ) ). | ||
| do_integration_test( | ||
| EXPORTING | ||
| test_type = test_type | ||
| CHANGING | ||
| act_data = test_type ). | ||
| test_type = VALUE #( special_char_enum = '>' ). | ||
| exp_json = VALUE #( | ||
| ( `{` ) | ||
| ( ` "specialCharEnum": "greaterThan"` ) | ||
| ( `}` ) ). | ||
| do_integration_test( | ||
| EXPORTING | ||
| test_type = test_type | ||
| CHANGING | ||
| act_data = test_type ). | ||
| test_type = VALUE #( special_char_enum = '&' ). | ||
| exp_json = VALUE #( | ||
| ( `{` ) | ||
| ( ` "specialCharEnum": "ampersand"` ) | ||
| ( `}` ) ). | ||
| do_integration_test( | ||
| EXPORTING | ||
| test_type = test_type | ||
| CHANGING | ||
| act_data = test_type ). | ||
| ENDMETHOD. | ||
|
|
||
| METHOD do_integration_test. | ||
| from_abap_to_json( | ||
| EXPORTING | ||
|
|
||
There was a problem hiding this comment.
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
escapeto escape xml?See https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENESCAPE_FUNCTIONS.html