No, because the newlines don't exist until after phase 1 is complete. Within Phase 1, only the outer loop looks for <LF> to truncate. After the %\n% gets replaced, the outer loop scanner continues with the next character after the replacement, so the <LF> is never seen by the scanner, and it is safe.
Dave Benham
Examination of Linefeeds with CALL
Moderator: DosItHelp
Re: Examination of Linefeeds with CALL
Hi Dave,
it's hard to remember all the problems parsing CALL/LF variables.
I retested some of the behaviour and I suppose your rules are correct now.
jeb
it's hard to remember all the problems parsing CALL/LF variables.
I retested some of the behaviour and I suppose your rules are correct now.
jeb
Re: Examination of Linefeeds with CALL
Below is evidence that Phase 0 preserves the end of line newline, and that phase 1 truly truncates the line at the first appearing newline not within expanding percents. Also, percent expansion error is not fatal after CALL.
It is important that the last line of the script does not end with a newline.
Dave Benham
It is important that the last line of the script does not end with a newline.
Code: Select all
@echo off
if "%~1" neq "" goto %1
setlocal
set var=CONTENT
(set \n=^
%= Creates a newline character =%
)
for /l %%N in (1 1 4) do (
echo ====== TEST %%N ======
cmd /v:on /c ^""%~f0" test%%N^"
echo --------------------
)
exit /b
:test1
call echo %%var:=WRONG SYNTAX!\n!%% NEWLINE PRESERVED WITHIN PERCENTS
echo The syntax error is not fatal after CALL
exit /b
:test2
call echo Line truncated at newline so no error!\n! %%var:=WRONG SYNTAX%%
exit /b
:test3
%var:=WRONG SYNTAX% THE END-OF-LINE NEWLINE IS PRESERVED AFTER PHASE 0
:test4
%var:=WRONG SYNTAX% THIS LINE HAS NO NEWLINE, SO ERROR MESSAGE NOT SPLIT
OUTPUT wrote: ====== TEST 1 ======
=WRONG SYNTAX
% NEWLINE PRESERVED WITHIN PERCENTS was unexpected at this time.
The syntax error is not fatal after CALL
--------------------
====== TEST 2 ======
Line truncated at newline so no error
--------------------
====== TEST 3 ======
=WRONG SYNTAX% THE END-OF-LINE NEWLINE IS PRESERVED AFTER PHASE 0
was unexpected at this time.
The syntax of the command is incorrect.
--------------------
====== TEST 4 ======
=WRONG SYNTAX% THIS LINE HAS NO NEWLINE, SO ERROR MESSAGE NOT SPLIT was unexpected at this time.
The syntax of the command is incorrect.
--------------------
Dave Benham
Re: Examination of Linefeeds with CALL
I just realized I had to make another change to step 2.3 in the phase rules - Both the search and replace terms allow <LF> characters.
I also corrected step 5.2 in delayed expansion to also allow <LF> in search and replace terms. Not sure why this one wasn't caught ages ago.
Dave Benham
I also corrected step 5.2 in delayed expansion to also allow <LF> in search and replace terms. Not sure why this one wasn't caught ages ago.
Dave Benham