Skip to content

Commit bb95eb4

Browse files
fix false positive on attempt to escape whitespace in qw()
..originally added in GH #23403.
1 parent 8914207 commit bb95eb4

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

t/lib/warnings/toke

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,33 @@ EXPECT
375375
Possible attempt to escape whitespace in qw() list at - line 3.
376376
########
377377
# toke.c
378+
use warnings 'qw';
379+
@a = qw( foo bar \ baz );
380+
EXPECT
381+
Possible attempt to escape whitespace in qw() list at - line 3.
382+
########
383+
# toke.c
384+
use warnings 'qw';
385+
@a = qw(\ );
386+
EXPECT
387+
Possible attempt to escape whitespace in qw() list at - line 3.
388+
########
389+
# toke.c
390+
use warnings 'qw';
391+
@a = qw(\\ );
392+
EXPECT
393+
########
394+
# toke.c
395+
use warnings 'qw';
396+
@a = qw( \\ );
397+
EXPECT
398+
########
399+
# toke.c
400+
use warnings 'qw';
401+
@a = qw( foo bar \\ baz );
402+
EXPECT
403+
########
404+
# toke.c
378405
use warnings 'syntax' ;
379406
print ("");
380407
print ("") and $x = 1;

toke.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5820,13 +5820,14 @@ yyl_qw(pTHX_ char *s, STRLEN len)
58205820
int warned_comment = warned_comma;
58215821
int warned_escape = warned_comma;
58225822
char *d = SvPV_force(PL_lex_stuff, len);
5823+
const STRLEN orig_len = len;
58235824
while (len) {
58245825
for (; isSPACE(*d) && len; --len, ++d)
58255826
/**/;
58265827
if (len) {
58275828
SV *sv;
58285829
const char *b = d;
5829-
if (!warned_comma || !warned_comment) {
5830+
if (!warned_comma || !warned_comment || !warned_escape) {
58305831
for (; !isSPACE(*d) && len; --len, ++d) {
58315832
if (!warned_comma && *d == ',') {
58325833
warner(packWARN(WARN_QW),
@@ -5838,7 +5839,8 @@ yyl_qw(pTHX_ char *s, STRLEN len)
58385839
"Possible attempt to put comments in qw() list");
58395840
++warned_comment;
58405841
}
5841-
else if (!warned_escape && *d == '\\' && len > 1 && isSPACE(*(d+1)) ) {
5842+
else if (!warned_escape && *d == '\\' && len > 1 && isSPACE(*(d+1))
5843+
&& (len == orig_len || *(d-1) != '\\')) {
58425844
warner(packWARN(WARN_QW),
58435845
"Possible attempt to escape whitespace in qw() list");
58445846
++warned_escape;

0 commit comments

Comments
 (0)