From 6e2752fc7008cccdb44adad0466e3e943269b0d7 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 14 Nov 2021 06:24:29 -0800 Subject: [PATCH] fix issue c109, 's s(..)(.)sss' --- dev-bin/run_tokenizer_tests.pl.data | 5 +++++ lib/Perl/Tidy/Tokenizer.pm | 8 +++++++- local-docs/BugLog.pod | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/dev-bin/run_tokenizer_tests.pl.data b/dev-bin/run_tokenizer_tests.pl.data index db0a24fc..2e1779cf 100644 --- a/dev-bin/run_tokenizer_tests.pl.data +++ b/dev-bin/run_tokenizer_tests.pl.data @@ -149,3 +149,8 @@ print $fh <6>; # error ==> c106.in <== my$seed=$$^$^T; + +==> c109.in <== +s s(..)(.)sss +; + diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 54c7733c..73739d0c 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -8821,7 +8821,8 @@ sub follow_quoted_string { "Note: alphanumeric quote delimiter ($beginning_tok) \n"); } - while ( $i < $max_token_index ) { + # Note: changed < to <= here to fix c109. Relying on extra end blanks. + while ( $i <= $max_token_index ) { if ( $quote_pos == 0 || ( $i < 0 ) ) { $tok = $rtokens->[ ++$i ]; @@ -8849,6 +8850,11 @@ sub follow_quoted_string { $quoted_string .= substr( $tok, $old_pos, $quote_pos - $old_pos - 1 ); + # NOTE: any quote modifiers will be at the end of '$tok'. If we + # wanted to check them, this is the place to get them. But + # this quote form is rarely used in practice, so it isn't + # worthwhile. + $quote_depth--; if ( $quote_depth == 0 ) { diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 790e9950..c4539402 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,23 @@ =over 4 +=item B + +Automated random testing produced an error tokenizing the following code +fragment: + + s s(..)(.)sss + ; + +This is equivalent to 's/(..)(.)//s' with 's' as the delimiter instead of '/'. +It was tokenized correctly except when the final 's' was followed by a newline, +as in the example. When the delimiter is a letter rather than a punctuation +character, perltidy exercises some seldom-used code which had an off-by-one +loop limit. This has been fixed. + +12 Nov 2021. + + =item B Automated random testing produced an error tokenizing the following fragment: -- 2.39.5