Fix bug in syntax parser of GET DATA /TYPE=TXT
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 21 Apr 2016 10:39:36 +0000 (12:39 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Thu, 21 Apr 2016 10:39:36 +0000 (12:39 +0200)
Fixed a bug which manifested itself when GET DATA /TYPE=TXT was
passed a variable name which happened also to be a token identifier.
The actual bug might also have caused other ill effects, but seems
to have been masked.

Reported-by: Rob L
src/language/data-io/get-data.c
src/language/lexer/format-parser.c
tests/language/data-io/get-data-txt.at

index e3a93b1738d0324be41f34c49200b7c5b5b3b0ce..fd1e68de889f11440d621822bcfddb58c6745d50 100644 (file)
@@ -617,18 +617,20 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
           lex_get (lexer);
         }
 
-      if (!lex_force_id (lexer)
-          || !dict_id_is_valid (dict, lex_tokcstr (lexer), true))
-        goto error;
       name = xstrdup (lex_tokcstr (lexer));
+      if (!lex_force_id (lexer)
+          || !dict_id_is_valid (dict, name, true))
+       {
+         goto error;
+       }
       lex_get (lexer);
-
       if (type == DP_DELIMITED)
         {
           if (!parse_format_specifier (lexer, &input)
-              || !fmt_check_input (&input))
-            goto error;
-
+             || !fmt_check_input (&input))
+           {
+             goto error;
+           }
           output = fmt_for_output_from_input (&input);
         }
       else
@@ -648,14 +650,12 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
               msg (SE, _("Unknown format type `%s'."), fmt_type_name);
               goto error;
             }
-
           /* Compose input format. */
           input.type = fmt_type;
           input.w = lc - fc + 1;
           input.d = 0;
           if (!fmt_check_input (&input))
             goto error;
-
           /* Compose output format. */
           if (w != 0)
             {
@@ -668,7 +668,6 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
           else
             output = fmt_for_output_from_input (&input);
         }
-
       v = dict_create_var (dict, name, fmt_var_width (&input));
       if (v == NULL)
         {
@@ -676,7 +675,6 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds)
           goto error;
         }
       var_set_both_formats (v, &output);
-
       if (type == DP_DELIMITED)
         data_parser_add_delimited_field (parser, &input,
                                          var_get_case_index (v),
index 78af09da311e2d2af24f5c9a410e68311f6f769a..2c05335ff984fa711bacba8920f682cb01c358ee 100644 (file)
@@ -40,7 +40,7 @@ parse_abstract_format_specifier__ (struct lexer *lexer,
   struct substring type_ss, width_ss, decimals_ss;
   bool has_decimals;
 
-  if (lex_token (lexer) != T_ID)
+  if (lex_token (lexer) != T_ID && lex_token (lexer) != T_STRING)
     goto error;
 
   /* Extract pieces. */
index b0b2616f7ae44cbc02740f0b383f6c957e1cc3b2..53f5d4fddc26b83645ff26314c96a8b4939d7c7f 100644 (file)
@@ -343,3 +343,40 @@ AT_CHECK([pspp -o pspp.csv x.sps], [1], [ignore])
 AT_CLEANUP
 
 
+
+AT_SETUP([GET DATA /TYPE=txt bug])
+
+
+AT_DATA([thing.txt], [dnl
+foo, title, last
+1, this, 1
+2, that, 2
+3, other, 3
+])
+
+AT_DATA([x.sps], [dnl
+GET DATA
+  /TYPE=TXT
+  /FILE="thing.txt"
+  /ARRANGEMENT=DELIMITED
+  /DELCASE=LINE
+  /FIRSTCASE=2
+  /DELIMITERS=","
+  /VARIABLES=foo F1.0
+    title A8
+    last F2.0.
+
+list.
+])
+
+AT_CHECK([pspp -O format=csv x.sps], [0], [dnl
+Table: Data List
+foo,title,last
+1,this   ,1
+2,that   ,2
+3,other  ,3
+])
+
+AT_CLEANUP
+
+