Skip to content
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

update #8

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 172 additions & 4 deletions cloud/zcl_abapgit_gui_event.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ TYPES: BEGIN OF ty,
TYPES tihttpnvp TYPE STANDARD TABLE OF ty WITH DEFAULT KEY.
INTERFACES zif_abapgit_gui_event .

CLASS-METHODS class_constructor .

CLASS-METHODS new
IMPORTING
!ii_gui_services TYPE REF TO zif_abapgit_gui_services OPTIONAL
Expand All @@ -33,6 +35,8 @@ TYPES tihttpnvp TYPE STANDARD TABLE OF ty WITH DEFAULT KEY.
DATA mo_query TYPE REF TO zcl_abapgit_string_map.
DATA mo_form_data TYPE REF TO zcl_abapgit_string_map.

CLASS-DATA gv_non_breaking_space TYPE string .

METHODS fields_to_map
IMPORTING
it_fields TYPE tihttpnvp
Expand All @@ -41,6 +45,40 @@ TYPES tihttpnvp TYPE STANDARD TABLE OF ty WITH DEFAULT KEY.
RAISING
zcx_abapgit_exception.

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
RETURNING
VALUE(rt_fields) TYPE tihttpnvp .
CLASS-METHODS parse_fields
IMPORTING
!iv_string TYPE clike
!iv_upper_cased TYPE abap_bool DEFAULT abap_false
RETURNING
VALUE(rt_fields) TYPE tihttpnvp .

CLASS-METHODS parse_fields_upper_case_name
IMPORTING
!iv_string TYPE clike
RETURNING
VALUE(rt_fields) TYPE tihttpnvp .

CLASS-METHODS translate_postdata
IMPORTING
!it_postdata TYPE zif_abapgit_html_viewer=>ty_post_data
RETURNING
VALUE(rv_string) TYPE string .

CLASS-METHODS field_keys_to_upper
CHANGING
!ct_fields TYPE tihttpnvp .
CLASS-METHODS unescape
IMPORTING
!iv_string TYPE string
RETURNING
VALUE(rv_string) TYPE string .

ENDCLASS.


Expand Down Expand Up @@ -88,8 +126,7 @@ CLASS zcl_abapgit_gui_event IMPLEMENTATION.
METHOD zif_abapgit_gui_event~form_data.

IF mo_form_data IS NOT BOUND.
mo_form_data = fields_to_map(
zcl_abapgit_html_action_utils=>parse_post_form_data( zif_abapgit_gui_event~mt_postdata ) ).
mo_form_data = fields_to_map( parse_post_form_data( zif_abapgit_gui_event~mt_postdata ) ).
mo_form_data->freeze( ).
ENDIF.
ro_string_map = mo_form_data.
Expand All @@ -100,11 +137,142 @@ CLASS zcl_abapgit_gui_event IMPLEMENTATION.
METHOD zif_abapgit_gui_event~query.

IF mo_query IS NOT BOUND.
mo_query = fields_to_map(
zcl_abapgit_html_action_utils=>parse_fields( zif_abapgit_gui_event~mv_getdata ) ).
mo_query = fields_to_map( parse_fields( zif_abapgit_gui_event~mv_getdata ) ).
mo_query->freeze( ).
ENDIF.
ro_string_map = mo_query.

ENDMETHOD.

METHOD parse_fields_upper_case_name.

rt_fields = parse_fields(
iv_string = iv_string
iv_upper_cased = abap_true ).

ENDMETHOD.


METHOD parse_post_form_data.

DATA lv_serialized_post_data TYPE string.

lv_serialized_post_data = translate_postdata( it_post_data ).
IF iv_upper_cased = abap_true.
rt_fields = parse_fields_upper_case_name( lv_serialized_post_data ).
ELSE.
rt_fields = parse_fields( lv_serialized_post_data ).
ENDIF.

ENDMETHOD.

METHOD parse_fields.

DATA:
lt_substrings TYPE string_table,
ls_field LIKE LINE OF rt_fields.

FIELD-SYMBOLS <lv_substring> LIKE LINE OF lt_substrings.

SPLIT iv_string AT '&' INTO TABLE lt_substrings.

LOOP AT lt_substrings ASSIGNING <lv_substring>.

CLEAR ls_field.
" On attempt to change unescaping -> run unit tests to check !

" Unescape name and value separately
ls_field-name = unescape( substring_before(
val = <lv_substring>
sub = '=' ) ).

ls_field-value = unescape( substring_after(
val = <lv_substring>
sub = '=' ) ).

IF ls_field IS INITIAL. " Not a field with proper structure
CONTINUE.
ENDIF.

APPEND ls_field TO rt_fields.

ENDLOOP.

IF iv_upper_cased = abap_true.
field_keys_to_upper( CHANGING ct_fields = rt_fields ).
ENDIF.

ENDMETHOD.


METHOD translate_postdata.

DATA: lt_post_data TYPE zif_abapgit_html_viewer=>ty_post_data,
ls_last_line LIKE LINE OF it_postdata,
lv_last_line_index TYPE i.

IF it_postdata IS INITIAL.
RETURN. "Nothing to do
ENDIF.

lt_post_data = it_postdata.

"Save the last line for separate merge, because we don't need its trailing spaces
WHILE ls_last_line IS INITIAL.
lv_last_line_index = lines( lt_post_data ).
READ TABLE lt_post_data INTO ls_last_line INDEX lv_last_line_index.
"Avoid trailing null values (see isssue #4832)
"todo, keep until SAP GUI for Java is fixed (remove on 2022-12-31)
ls_last_line = replace( val = ls_last_line
sub = zcl_abapgit_git_utils=>get_null( )
with = space
occ = 0 ).
DELETE lt_post_data INDEX lv_last_line_index.
ENDWHILE.

CONCATENATE LINES OF lt_post_data INTO rv_string
IN CHARACTER MODE RESPECTING BLANKS.
CONCATENATE rv_string ls_last_line INTO rv_string
IN CHARACTER MODE.

ENDMETHOD.

METHOD field_keys_to_upper.

FIELD-SYMBOLS <ls_field> LIKE LINE OF ct_fields.

LOOP AT ct_fields ASSIGNING <ls_field>.
<ls_field>-name = to_upper( <ls_field>-name ).
ENDLOOP.

ENDMETHOD.

METHOD unescape.

* do not use cl_http_utility as it does strange things with the encoding
rv_string = iv_string.

* todo, more to be added here
REPLACE ALL OCCURRENCES OF '%3A' IN rv_string WITH ':' IGNORING CASE.
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.

METHOD class_constructor.

CONSTANTS lc_nbsp TYPE xstring VALUE 'C2A0'. " &nbsp;

TRY.
gv_non_breaking_space = zcl_abapgit_convert=>xstring_to_string_utf8( lc_nbsp ).
CATCH zcx_abapgit_exception.
ASSERT 0 = 1.
ENDTRY.

ENDMETHOD.

ENDCLASS.
165 changes: 0 additions & 165 deletions cloud/zcl_abapgit_gui_event.clas.testclasses.abap

This file was deleted.

4 changes: 2 additions & 2 deletions cloud/zcl_abapgit_gui_page_addofflin.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ENDCLASS.



CLASS ZCL_ABAPGIT_GUI_PAGE_ADDOFFLIN IMPLEMENTATION.
CLASS zcl_abapgit_gui_page_addofflin IMPLEMENTATION.


METHOD choose_labels.
Expand Down Expand Up @@ -220,7 +220,7 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_ADDOFFLIN IMPLEMENTATION.

mo_form_data->set(
iv_key = c_id-package
iv_val = zcl_abapgit_services_basis=>create_package(
iv_val = zcl_abapgit_services_repo=>create_package(
iv_prefill_package = |{ mo_form_data->get( c_id-package ) }| ) ).
IF mo_form_data->get( c_id-package ) IS NOT INITIAL.
mo_validation_log = validate_form( mo_form_data ).
Expand Down
Loading