From: Gurusamy Sarathy Date: Sun, 19 Jul 1998 06:07:51 +0000 (+0000) Subject: fix and test handling of literal newlines in heredocs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c6f14548d7bd301fc081005522b7fbe495c9b172;p=p5sagit%2Fp5-mst-13.2.git fix and test handling of literal newlines in heredocs From: Gisle Aas Date: 17 Jul 1998 14:58:25 +0200 Message-ID: Subject: Re: [PATCH _71] CRs et al -- From: larry@wall.org (Larry Wall) Date: Fri, 17 Jul 1998 09:32:35 -0700 Message-Id: <199807171632.JAA12959@wall.org> Subject: Re: [PATCH _71] CRs et al p4raw-id: //depot/perl@1545 --- diff --git a/t/comp/multiline.t b/t/comp/multiline.t index fc1eedc..ed418b8 100755 --- a/t/comp/multiline.t +++ b/t/comp/multiline.t @@ -9,11 +9,15 @@ open(try,'>Comp.try') || (die "Can't open temp file."); $x = 'now is the time for all good men to come to. + + +! + '; $y = 'now is the time' . "\n" . 'for all good men' . "\n" . -'to come to.' . "\n"; +'to come to.' . "\n\n\n!\n\n"; if ($x eq $y) {print "ok 1\n";} else {print "not ok 1\n";} @@ -30,7 +34,7 @@ while () { if ($z eq $y) {print "ok 2\n";} else {print "not ok 2\n";} -if ($count == 3) {print "ok 3\n";} else {print "not ok 3\n";} +if ($count == 7) {print "ok 3\n";} else {print "not ok 3\n";} $_ = ($^O eq 'MSWin32') ? `type Comp.try` : `cat Comp.try`; diff --git a/toke.c b/toke.c index 9685fc3..d1afa50 100644 --- a/toke.c +++ b/toke.c @@ -5246,7 +5246,9 @@ scan_heredoc(register char *s) bufend = SvPVX(linestr) + SvCUR(linestr); #ifdef TMP_CRLF_PATCH if (bufend - linestart >= 2) { - if (bufend[-2] == '\r' || bufend[-2] == '\n') { + if ((bufend[-2] == '\r' && bufend[-1] == '\n') || + (bufend[-2] == '\n' && bufend[-1] == '\r')) + { bufend[-2] = '\n'; bufend--; SvCUR_set(linestr, bufend - SvPVX(linestr)); @@ -5543,7 +5545,9 @@ scan_str(char *start) #ifdef TMP_CRLF_PATCH if (to - SvPVX(sv) >= 2) { - if (to[-2] == '\r' || to[-2] == '\n') { + if ((to[-2] == '\r' && to[-1] == '\n') || + (to[-2] == '\n' && to[-1] == '\r')) + { to[-2] = '\n'; to--; SvCUR_set(sv, to - SvPVX(sv));