]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix encoding of quoted values (<rdar://problem/19736672>)
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Tue, 26 Jan 2016 18:35:03 +0000 (18:35 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Tue, 26 Jan 2016 18:35:03 +0000 (18:35 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@13057 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES-2.1.txt
cups/encode.c
cups/testoptions.c

index 9c975c4c94cfac597e62efa27a4f891e3e9aa06b..4eb9939287d310e12841d5ac5eb0b95b4abd3757 100644 (file)
@@ -15,6 +15,8 @@ CHANGES IN CUPS V2.1.3
          (<rdar://problem/24137160>)
        - The "lp -H resume" command did not reset the "job-state-reasons"
          attribute value (STR #4752)
+       - cupsEncodeOptions2 incorrectly handled escaped values
+         (<rdar://problem/19736672>)
        - Localization fix (STR #4756)
 
 
index 67a51667b412b500df00de8ed89aaa78569dc6f9..3bdfac8a4a5be999078c4fa857953acd46f55e4e 100644 (file)
@@ -542,14 +542,13 @@ cupsEncodeOptions2(
        else if (*sep == ',' && !quote)
          count ++;
        else if (*sep == '\\' && sep[1])
-         sep ++;
+         sep += 2;
       }
     }
     else
       count = 1;
 
-    DEBUG_printf(("2cupsEncodeOptions2: option=\"%s\", count=%d",
-                  option->name, count));
+    DEBUG_printf(("2cupsEncodeOptions2: option=\"%s\", value=\"%s\", count=%d", option->name, option->value, count));
 
    /*
     * Allocate memory for the attribute values...
@@ -633,6 +632,7 @@ cupsEncodeOptions2(
            * Skip quoted character...
            */
 
+           memmove(sep, sep + 1, strlen(val));
            sep ++;
          }
        }
index 1cd72794fae349b7e77929771fa10e344fefd2cc..6c939e8c363ab628a5bf02db37bd4e7da6554735 100644 (file)
@@ -1,21 +1,17 @@
 /*
  * "$Id$"
  *
- *   Option test program for CUPS.
+ * Option unit test program for CUPS.
  *
- *   Copyright 2008-2010 by Apple Inc.
+ * Copyright 2008-2016 by Apple Inc.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   main() - Test option processing functions.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -37,6 +33,9 @@ main(int  argc,                               /* I - Number of command-line arguments */
                num_options;            /* Number of options */
   cups_option_t        *options;               /* Options */
   const char   *value;                 /* Value of an option */
+  ipp_t                *request;               /* IPP request */
+  ipp_attribute_t *attr;               /* IPP attribute */
+  int          count;                  /* Number of attributes */
 
 
   if (argc == 1)
@@ -53,11 +52,12 @@ main(int  argc,                             /* I - Number of command-line arguments */
                                   "baz={param1=1 param2=2} "
                                   "foobar=FOO\\ BAR "
                                   "barfoo=barfoo "
-                                  "barfoo=\"\'BAR FOO\'\"", 0, &options);
+                                  "barfoo=\"\'BAR FOO\'\" "
+                                  "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options);
 
-    if (num_options != 5)
+    if (num_options != 6)
     {
-      printf("FAIL (num_options=%d, expected 5)\n", num_options);
+      printf("FAIL (num_options=%d, expected 6)\n", num_options);
       status ++;
     }
     else if ((value = cupsGetOption("foo", num_options, options)) == NULL ||
@@ -91,6 +91,71 @@ main(int  argc,                              /* I - Number of command-line arguments */
       printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value);
       status ++;
     }
+    else if ((value = cupsGetOption("auth-info", num_options, options)) == NULL ||
+             strcmp(value, "user,pass\\,word\\\\"))
+    {
+      printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value);
+      status ++;
+    }
+    else
+      puts("PASS");
+
+    fputs("cupsEncodeOptions2: ", stdout);
+    request = ippNew();
+    ippSetOperation(request, IPP_OP_PRINT_JOB);
+
+    cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
+    for (count = 0, attr = ippFirstAttribute(request); attr; attr = ippNextAttribute(request), count ++);
+    if (count != 6)
+    {
+      printf("FAIL (%d attributes, expected 6)\n", count);
+      status ++;
+    }
+    else if ((attr = ippFindAttribute(request, "foo", IPP_TAG_ZERO)) == NULL)
+    {
+      puts("FAIL (Unable to find attribute \"foo\")");
+      status ++;
+    }
+    else if (ippGetValueTag(attr) != IPP_TAG_NAME)
+    {
+      printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr)));
+      status ++;
+    }
+    else if (ippGetCount(attr) != 1)
+    {
+      printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr));
+      status ++;
+    }
+    else if (strcmp(ippGetString(attr, 0, NULL), "1234"))
+    {
+      printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr, 0, NULL));
+      status ++;
+    }
+    else if ((attr = ippFindAttribute(request, "auth-info", IPP_TAG_ZERO)) == NULL)
+    {
+      puts("FAIL (Unable to find attribute \"auth-info\")");
+      status ++;
+    }
+    else if (ippGetValueTag(attr) != IPP_TAG_TEXT)
+    {
+      printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr)));
+      status ++;
+    }
+    else if (ippGetCount(attr) != 2)
+    {
+      printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr));
+      status ++;
+    }
+    else if (strcmp(ippGetString(attr, 0, NULL), "user"))
+    {
+      printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr, 0, NULL));
+      status ++;
+    }
+    else if (strcmp(ippGetString(attr, 1, NULL), "pass,word\\"))
+    {
+      printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr, 1, NULL));
+      status ++;
+    }
     else
       puts("PASS");
   }