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

Fix no escaping for standard escapes in regular expressions #315

Merged
merged 8 commits into from
Aug 6, 2024
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
2 changes: 1 addition & 1 deletion src/zcl_aff_abap_doc_parser.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ CLASS zcl_aff_abap_doc_parser IMPLEMENTATION.

DATA(string_to_parse) = abap_doc_string.

FIND ALL OCCURRENCES OF PCRE `\$pattern[\s]*(:[\s]*)?'([^']*)'` IN string_to_parse RESULTS DATA(result_table).
FIND ALL OCCURRENCES OF PCRE `\$pattern[\s]*(:[\s]*)?'(\S*)'` IN string_to_parse RESULTS DATA(result_table).

IF lines( result_table ) = 0.
DATA(msg) = parser_log->get_message_text( msgno = 109 msgv1 = CONV #( abap_doc_annotation-pattern ) ).
Expand Down
1 change: 0 additions & 1 deletion src/zcl_aff_abap_doc_parser.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ CLASS ltcl_aff_abap_doc_parser IMPLEMENTATION.
exp_text = |There are several occurrences of annotation { zcl_aff_abap_doc_parser=>abap_doc_annotation-pattern } . First valid is used|
exp_type = zif_aff_log=>c_message_type-info
exp_component_name = `Component Name` ).

ENDMETHOD.

ENDCLASS.
24 changes: 22 additions & 2 deletions src/zcl_aff_test_types.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CLASS zcl_aff_test_types DEFINITION
END OF struc_link_wrong_type.

TYPES:
"! $pattern '[a-Z]*'
"! $pattern '[a-z]*'
ty_string TYPE string.

TYPES:
Expand All @@ -86,10 +86,30 @@ CLASS zcl_aff_test_types DEFINITION
BEGIN OF string_pattern_simple,
"! <p class="shorttext">String with pattern</p>
"! description
"! $pattern '[a-Z]*'
"! $pattern '[a-z]*'
string_pattern TYPE string,
END OF string_pattern_simple.

TYPES:
"! <p class="shorttext">Structure With Pattern Annotation</p>
"! Structure with pattern annotation
BEGIN OF string_pattern_escape_sequence,
"! <p class="shorttext">String with pattern</p>
"! description
"! $pattern '\n\t\r'
string_pattern TYPE string,
END OF string_pattern_escape_sequence.

TYPES:
"! <p class="shorttext">Structure With Pattern Annotation</p>
"! Structure with pattern annotation
BEGIN OF string_pattern_quotes,
"! <p class="shorttext">String with pattern</p>
"! description
"! $pattern '"\"''
string_pattern TYPE string,
END OF string_pattern_quotes.

TYPES:
"! in ST val(I()) only allow integers
"! $values {@link zcl_aff_test_types.data:co_enum}
Expand Down
2 changes: 2 additions & 0 deletions src/zcl_aff_writer_json_schema.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ CLASS zcl_aff_writer_json_schema IMPLEMENTATION.
ENDIF.
ENDIF.
IF abap_doc-pattern IS NOT INITIAL.
REPLACE ALL OCCURRENCES OF '\' IN abap_doc-pattern WITH '\\'.
REPLACE ALL OCCURRENCES OF '"' IN abap_doc-pattern WITH '\"'.
write_tag( |"pattern": "{ abap_doc-pattern }",| ).
ENDIF.
ENDMETHOD.
Expand Down
60 changes: 57 additions & 3 deletions src/zcl_aff_writer_json_schema.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,9 @@ CLASS ltcl_json_writer_abap_doc DEFINITION FINAL FOR TESTING
content_media_type_string FOR TESTING RAISING cx_static_check,
encoding_type_next_level FOR TESTING RAISING cx_static_check,
pattern_simple FOR TESTING RAISING cx_static_check,
pattern_complex FOR TESTING RAISING cx_static_check.
pattern_complex FOR TESTING RAISING cx_static_check,
pattern_escape_sequence FOR TESTING RAISING cx_static_check,
pattern_with_quotes FOR TESTING RAISING cx_static_check.

ENDCLASS.

Expand Down Expand Up @@ -2806,7 +2808,7 @@ CLASS ltcl_json_writer_abap_doc IMPLEMENTATION.
( ` "title": "String with pattern",` )
( ` "description": "description",` )
( ` "type": "string", ` )
( ` "pattern": "[a-Z]*" ` )
( ` "pattern": "[a-z]*" ` )
( ` } ` )
( ` }, ` )
( ` "additionalProperties": false ` )
Expand All @@ -2832,7 +2834,59 @@ CLASS ltcl_json_writer_abap_doc IMPLEMENTATION.
( ` "title": "String with pattern",` )
( ` "description": "description",` )
( ` "type": "string", ` )
( ` "pattern": "[a-Z]*" ` )
( ` "pattern": "[a-z]*" ` )
( ` } ` )
( ` }, ` )
( ` "additionalProperties": false ` )
( ` } ` )
( ) ).
zcl_aff_tools_unit_test_helper=>assert_equals_ignore_spaces( act_data = act_schema exp_data = exp_schema ).
log = cut->zif_aff_writer~get_log( ).
zcl_aff_tools_unit_test_helper=>assert_log_has_no_message( log = log message_severity_threshold = zif_aff_log=>c_message_type-info ).
ENDMETHOD.

METHOD pattern_escape_sequence.
DATA(act_schema) = test_generator->generate_type( VALUE zcl_aff_test_types=>string_pattern_escape_sequence( ) ).
DATA(exp_schema) = VALUE string_table(
( ` { ` )
( | "$comment": "This file is autogenerated, do not edit manually, see { zcl_aff_writer_json_schema=>c_link_to_repository } for more information.", | )
( | "$schema": "{ zcl_aff_writer_json_schema=>c_schema_specification }",| )
( | "$id": "{ schema_id }",| )
( ` "title": "Structure With Pattern Annotation", ` )
( ` "description": "Structure with pattern annotation", ` )
( ` "type": "object", ` )
( ` "properties": { ` )
( ` "stringPattern": { ` )
( ` "title": "String with pattern",` )
( ` "description": "description",` )
( ` "type": "string", ` )
( ` "pattern": "\\n\\t\\r" ` )
( ` } ` )
( ` }, ` )
( ` "additionalProperties": false ` )
( ` } ` )
( ) ).
zcl_aff_tools_unit_test_helper=>assert_equals_ignore_spaces( act_data = act_schema exp_data = exp_schema ).
log = cut->zif_aff_writer~get_log( ).
zcl_aff_tools_unit_test_helper=>assert_log_has_no_message( log = log message_severity_threshold = zif_aff_log=>c_message_type-info ).
ENDMETHOD.

METHOD pattern_with_quotes.
DATA(act_schema) = test_generator->generate_type( VALUE zcl_aff_test_types=>string_pattern_quotes( ) ).
DATA(exp_schema) = VALUE string_table(
( ` { ` )
( | "$comment": "This file is autogenerated, do not edit manually, see { zcl_aff_writer_json_schema=>c_link_to_repository } for more information.", | )
( | "$schema": "{ zcl_aff_writer_json_schema=>c_schema_specification }",| )
( | "$id": "{ schema_id }",| )
( ` "title": "Structure With Pattern Annotation", ` )
( ` "description": "Structure with pattern annotation", ` )
( ` "type": "object", ` )
( ` "properties": { ` )
( ` "stringPattern": { ` )
( ` "title": "String with pattern",` )
( ` "description": "description",` )
( ` "type": "string", ` )
( ` "pattern": "\"\\\"'" ` )
( ` } ` )
( ` }, ` )
( ` "additionalProperties": false ` )
Expand Down
Loading