]> granicus.if.org Git - imagemagick/commitdiff
Script parser - add line continuation in double quotes
authoranthony <anthony@git.imagemagick.org>
Thu, 19 Apr 2012 05:12:09 +0000 (05:12 +0000)
committeranthony <anthony@git.imagemagick.org>
Thu, 19 Apr 2012 05:12:09 +0000 (05:12 +0000)
MagickWand/script-token.c
MagickWand/tests/Makefile
MagickWand/tests/script-token-test-data.txt
MagickWand/tests/script-token-test-results.txt

index a9f1ba6eefb828fe0245b0718dfbdbb111b39c62..d05e2c2966b19dbc707892afd6ae4be5afabe106 100644 (file)
@@ -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:
index 3eef27123c41d935f038a2ef38028e8de8963a9d..8aba51026bccdf9b443990d60a3c2d940151a2ed 100644 (file)
@@ -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 -
index 4769b317e326166cde9cf658c821fc1a487fa4b6..cdea6d10f83ea51f74fd23451c9fa85e0f1c017d 100644 (file)
@@ -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"
index 8c5c5705319741788e1a030d01a6fcb5aca40f63..834eeb1277838a8a71f601249445b7b78b2507ec 100644 (file)
@@ -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"