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 4 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: 2 additions & 0 deletions src/zcl_aff_abap_doc_parser.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ CLASS zcl_aff_abap_doc_parser IMPLEMENTATION.

DATA(string_to_parse) = abap_doc_string.

REPLACE ALL OCCURRENCES OF PCRE `\\` IN string_to_parse WITH `\\`.
REPLACE ALL OCCURRENCES OF PCRE `\"` IN string_to_parse WITH `\\"`.
wurzka marked this conversation as resolved.
Show resolved Hide resolved
wurzka marked this conversation as resolved.
Show resolved Hide resolved
FIND ALL OCCURRENCES OF PCRE `\$pattern[\s]*(:[\s]*)?'([^']*)'` IN string_to_parse RESULTS DATA(result_table).

IF lines( result_table ) = 0.
Expand Down
14 changes: 14 additions & 0 deletions src/zcl_aff_abap_doc_parser.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CLASS ltcl_aff_abap_doc_parser DEFINITION FINAL FOR TESTING
METHODS pattern_no_single_quotes FOR TESTING RAISING cx_static_check.
METHODS pattern_no_value FOR TESTING RAISING cx_static_check.
METHODS pattern FOR TESTING RAISING cx_static_check.
METHODS pattern_with_escape_sequences FOR TESTING RAISING cx_static_check.

ENDCLASS.

Expand Down Expand Up @@ -661,4 +662,17 @@ CLASS ltcl_aff_abap_doc_parser IMPLEMENTATION.

ENDMETHOD.

METHOD pattern_with_escape_sequences.
DATA(abap_doc_to_parse) = `<p class="shorttext">Title</p> This is the description. $pattern '\\n\\t\\r[a-z]*\\"'`.
DATA(act_abap_doc) = parser->parse(
EXPORTING
component_name = `Component Name`
to_parse = abap_doc_to_parse
CHANGING
log = log ).
exp_abap_doc = VALUE #( title = `Title` description = `This is the description.` pattern = `\\n\\t\\r[a-z]*\\\"` ).
cl_abap_unit_assert=>assert_equals( exp = exp_abap_doc act = act_abap_doc ).
zcl_aff_tools_unit_test_helper=>assert_log_has_no_message( log = log message_severity_threshold = zif_aff_log=>c_message_type-info ).
ENDMETHOD.

ENDCLASS.
4 changes: 2 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 '\\n\\t\\r[a-z]*\\"'
wurzka marked this conversation as resolved.
Show resolved Hide resolved
ty_string TYPE string.

TYPES:
Expand All @@ -86,7 +86,7 @@ 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.

Expand Down
4 changes: 2 additions & 2 deletions src/zcl_aff_writer_json_schema.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -2806,7 +2806,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 +2832,7 @@ CLASS ltcl_json_writer_abap_doc IMPLEMENTATION.
( ` "title": "String with pattern",` )
( ` "description": "description",` )
( ` "type": "string", ` )
( ` "pattern": "[a-Z]*" ` )
( ` "pattern": "\\n\\t\\r[a-z]*\\\"" ` )
( ` } ` )
( ` }, ` )
( ` "additionalProperties": false ` )
Expand Down
Loading