From: anthony Date: Thu, 19 Apr 2012 05:12:09 +0000 (+0000) Subject: Script parser - add line continuation in double quotes X-Git-Tag: 7.0.1-0~5770 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3731b3404ecbe4be7fba906c91cd03d52f38e780;p=imagemagick Script parser - add line continuation in double quotes --- diff --git a/MagickWand/script-token.c b/MagickWand/script-token.c index a9f1ba6ee..d05e2c296 100644 --- a/MagickWand/script-token.c +++ b/MagickWand/script-token.c @@ -255,6 +255,7 @@ WandExport ScriptTokenInfo * DestroyScriptTokenInfo(ScriptTokenInfo *token_info) The EOL is defined as either '\r\n', or '\r', or '\n'. A '\r' on its own is converted into a '\n' to correctly handle raw input, typically due to 'copy-n-paste' of text files. + But a '\r\n' sequence is left ASIS for string handling */ #define GetChar(c) \ { \ @@ -370,13 +371,16 @@ WandExport MagickBooleanType GetScriptToken(ScriptTokenInfo *token_info) continue; } GetChar(c); - if (c == '\n' || c == '\r' ) + if (c == '\n') switch (state) { case IN_COMMENT: state=IN_WHITE; /* end comment */ + case IN_QUOTE: + if (quote != '"') + break; /* in double quotes only */ case IN_WHITE: case IN_TOKEN: - continue; /* line continuation (outside quotes and comment) */ + continue; /* line continuation - remove line feed */ } switch (state) { case IN_WHITE: diff --git a/MagickWand/tests/Makefile b/MagickWand/tests/Makefile index 3eef27123..8aba51026 100644 --- a/MagickWand/tests/Makefile +++ b/MagickWand/tests/Makefile @@ -18,3 +18,6 @@ script-token-test: script-token-test.c ../script-token.[ch] clean: rm -f $(tests) + +test_script: + script-token-test.sh | diff script-token-test-results.txt - diff --git a/MagickWand/tests/script-token-test-data.txt b/MagickWand/tests/script-token-test-data.txt index 4769b317e..cdea6d10f 100644 --- a/MagickWand/tests/script-token-test-data.txt +++ b/MagickWand/tests/script-token-test-data.txt @@ -31,10 +31,19 @@ Back\ slash\ escapes "µ ¶ ⨀ ⨁ ⨂" 测试用的汉字 -Lines__\ +Line__\ __Continuation -'quoted_newlines__ +"Double_Quoted_Line__\ +__Continuation" + +'Single_Quoted_Line__\ +__Continuation_NOT!' + +"double_quoted_newlines__ +__are_part_of_token" + +'single_quoted_newlines__ __are_part_of_token' "Last Token before EOF" diff --git a/MagickWand/tests/script-token-test-results.txt b/MagickWand/tests/script-token-test-results.txt index 8c5c57053..834eeb127 100644 --- a/MagickWand/tests/script-token-test-results.txt +++ b/MagickWand/tests/script-token-test-results.txt @@ -28,10 +28,15 @@ l=29, c=1, stat=0, len=64, token="Unicode charcaters are handled" l=30, c=1, stat=0, len=64, token="° ' ² ³ ` ´" l=31, c=1, stat=0, len=64, token="µ ¶ ⨀ ⨁ ⨂" l=32, c=1, stat=0, len=64, token="测试用的汉字" -l=34, c=1, stat=0, len=64, token="Lines____Continuation" -l=37, c=1, stat=0, len=64, token="quoted_newlines__ +l=34, c=1, stat=0, len=64, token="Line____Continuation" +l=37, c=1, stat=0, len=64, token="Double_Quoted_Line____Continuation" +l=40, c=1, stat=0, len=64, token="Single_Quoted_Line__\ +__Continuation_NOT!" +l=43, c=1, stat=0, len=64, token="double_quoted_newlines__ __are_part_of_token" -l=40, c=1, stat=0, len=64, token="Last Token before EOF" +l=46, c=1, stat=0, len=64, token="single_quoted_newlines__ +__are_part_of_token" +l=49, c=1, stat=0, len=64, token="Last Token before EOF" EOF Found l=1, c=1, stat=0, len=64, token="Next token bad quotes"