Fix commit message encoding (#5508)

* Fix commit message encoding

- Properly encode % and & symbols
- Add unit test for special characters

Closes https://github.com/abapGit/abapGit/issues/2448

* Exclude testclass

* Comment

* update to 2.0.17

* update to 2.0.18

Co-authored-by: Lars Hvam <larshp@hotmail.com>
This commit is contained in:
Marc Bernard 2022-05-05 15:29:38 +02:00 committed by GitHub
parent f3028e21c2
commit 1b4582bc03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 22 deletions

View File

@ -177,7 +177,10 @@
"exclude": ["/json/"]
},
"7bit_ascii": {
"exclude": ["zcl_abapgit_utils.clas.testclasses.abap"]
"exclude": [
"zcl_abapgit_utils.clas.testclasses.abap",
"zcl_abapgit_html_action_utils.clas.testclasses.abap"
]
},
"abapdoc": false,
"check_ddic": true,

View File

@ -26,8 +26,8 @@
},
"devDependencies": {
"@abaplint/cli": "^2.89.14",
"@abaplint/runtime": "^2.0.16",
"@abaplint/transpiler-cli": "^2.0.16",
"@abaplint/runtime": "^2.0.18",
"@abaplint/transpiler-cli": "^2.0.18",
"@abaplint/database-sqlite": "^2.0.11",
"abapmerge": "^0.14.3",
"c8": "^7.11.2",

View File

@ -6,8 +6,8 @@ CLASS zcl_abapgit_html_action_utils DEFINITION
CLASS-METHODS parse_post_form_data
IMPORTING
!it_post_data TYPE zif_abapgit_html_viewer=>ty_post_data
!iv_upper_cased TYPE abap_bool DEFAULT abap_false
!it_post_data TYPE zif_abapgit_html_viewer=>ty_post_data
!iv_upper_cased TYPE abap_bool DEFAULT abap_false
RETURNING
VALUE(rt_fields) TYPE tihttpnvp .
CLASS-METHODS parse_fields
@ -23,7 +23,7 @@ CLASS zcl_abapgit_html_action_utils DEFINITION
VALUE(rt_fields) TYPE tihttpnvp .
CLASS-METHODS translate_postdata
IMPORTING
!it_postdata TYPE zif_abapgit_html_viewer=>ty_post_data
!it_postdata TYPE zif_abapgit_html_viewer=>ty_post_data
RETURNING
VALUE(rv_string) TYPE string .
@ -90,14 +90,6 @@ ENDCLASS.
CLASS zcl_abapgit_html_action_utils IMPLEMENTATION.
METHOD class_constructor.
CONSTANTS lc_nbsp TYPE xstring VALUE 'C2A0'. " &nbsp;
gv_non_breaking_space = zcl_abapgit_convert=>xstring_to_string_utf8( lc_nbsp ).
ENDMETHOD.
METHOD add_field.
@ -123,6 +115,15 @@ CLASS zcl_abapgit_html_action_utils IMPLEMENTATION.
ENDMETHOD.
METHOD class_constructor.
CONSTANTS lc_nbsp TYPE xstring VALUE 'C2A0'. " &nbsp;
gv_non_breaking_space = zcl_abapgit_convert=>xstring_to_string_utf8( lc_nbsp ).
ENDMETHOD.
METHOD dbkey_encode.
DATA: lt_fields TYPE tihttpnvp.
@ -253,16 +254,16 @@ CLASS zcl_abapgit_html_action_utils IMPLEMENTATION.
LOOP AT lt_substrings ASSIGNING <lv_substring>.
CLEAR ls_field.
<lv_substring> = unescape( <lv_substring> ).
" On attempt to change unescaping -> run unit tests to check !
ls_field-name = substring_before(
" Unescape name and value separately
ls_field-name = unescape( substring_before(
val = <lv_substring>
sub = '=' ).
sub = '=' ) ).
ls_field-value = substring_after(
ls_field-value = unescape( substring_after(
val = <lv_substring>
sub = '=' ).
sub = '=' ) ).
IF ls_field IS INITIAL. " Not a field with proper structure
CONTINUE.
@ -341,9 +342,11 @@ CLASS zcl_abapgit_html_action_utils IMPLEMENTATION.
rv_string = iv_string.
* todo, more to be added here
REPLACE ALL OCCURRENCES OF '%3F' IN rv_string WITH '?'.
REPLACE ALL OCCURRENCES OF '%3D' IN rv_string WITH '='.
REPLACE ALL OCCURRENCES OF '%2f' IN rv_string WITH '/'.
REPLACE ALL OCCURRENCES OF '%3F' IN rv_string WITH '?' IGNORING CASE.
REPLACE ALL OCCURRENCES OF '%3D' IN rv_string WITH '=' IGNORING CASE.
REPLACE ALL OCCURRENCES OF '%2F' IN rv_string WITH '/' IGNORING CASE.
REPLACE ALL OCCURRENCES OF '%25' IN rv_string WITH '%' IGNORING CASE.
REPLACE ALL OCCURRENCES OF '%26' IN rv_string WITH '&' IGNORING CASE.
REPLACE ALL OCCURRENCES OF gv_non_breaking_space IN rv_string WITH ` `.
ENDMETHOD.

View File

@ -13,6 +13,7 @@ CLASS ltcl_html_action_utils DEFINITION FOR TESTING RISK LEVEL HARMLESS
METHODS parse_fields_wrong_format FOR TESTING.
METHODS parse_post_form_data FOR TESTING.
METHODS parse_fields_webgui FOR TESTING.
METHODS parse_fields_special_chars FOR TESTING.
PRIVATE SECTION.
@ -374,4 +375,22 @@ CLASS ltcl_html_action_utils IMPLEMENTATION.
ENDMETHOD.
METHOD parse_fields_special_chars.
DATA lv_string TYPE string.
" URL encoded data
lv_string = `TEST=!"#$%25%26'()*+,-./09:;<%3d>?@AZ[\]^_``az{|}~¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿`.
_given_string_is( lv_string ).
_when_fields_are_parsed( ).
_then_field_count_should_be( 1 ).
_then_fields_should_be(
iv_index = 1
iv_name = 'TEST'
iv_value = `!"#$%&'()*+,-./09:;<=>?@AZ[\]^_``az{|}~¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿` ).
ENDMETHOD.
ENDCLASS.