]> granicus.if.org Git - imagemagick/commitdiff
fix %l and %c in image property escapes
authoranthony <anthony@git.imagemagick.org>
Tue, 15 May 2012 00:09:16 +0000 (00:09 +0000)
committeranthony <anthony@git.imagemagick.org>
Tue, 15 May 2012 00:09:16 +0000 (00:09 +0000)
MagickCore/artifact.c
MagickCore/option.c
MagickCore/property.c

index 0d89019a48ab14251655772238534dc354d7e507..9f497dcda408895e6dcadbd68f180b228c3a2ee7 100644 (file)
@@ -247,8 +247,9 @@ MagickExport void DestroyImageArtifacts(Image *image)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  GetImageArtifact() gets a value associated with an image artifact.
+%  If the requested artifact is NULL return the first artifact.
 %
-%  Note, the artifact is a constant.  Do not attempt to free it.
+%  Note, returned string is a constant in the tree and should NOT be freed.
 %
 %  The format of the GetImageArtifact method is:
 %
@@ -444,10 +445,12 @@ MagickExport MagickBooleanType SetImageArtifact(Image *image,
   if (image->artifacts == (void *) NULL)
     image->artifacts=NewSplayTree(CompareSplayTreeString,
       RelinquishMagickMemory,RelinquishMagickMemory);
-  /* Delete artifact if NULL or empty */
-  if ((value == (const char *) NULL) || (*value == '\0'))
+
+  /* Delete artifact if NULL --  empty string values are valid! */
+  if (value == (const char *) NULL)
     return(DeleteImageArtifact(image,artifact));
-  /* add option to tree */
+
+  /* add artifact to splay-tree */
   status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
     ConstantString(artifact),ConstantString(value));
   return(status);
index c8ecdfd36f74830be59454268115c3e327e6d8ef..b9cd40fb86371f59d1c7ad2f80f4e0b76dfe1500 100644 (file)
@@ -2721,7 +2721,7 @@ MagickExport MagickBooleanType SetImageOption(ImageInfo *image_info,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
 
-  /* This should not be here! - but others might */
+  /* FUTURE: This should not be here! - but others might */
   if (LocaleCompare(option,"size") == 0)
     (void) CloneString(&image_info->size,value);
 
@@ -2734,7 +2734,7 @@ MagickExport MagickBooleanType SetImageOption(ImageInfo *image_info,
   if (value == (const char *) NULL)
     return(DeleteImageOption(image_info,option));
 
-  /* add option and return */
+  /* add option to splay-tree */
   return(AddValueToSplayTree((SplayTreeInfo *) image_info->options,
     ConstantString(option),ConstantString(value)));
 }
index 4f6d81a28ba2f0f6e86db2852de5de4c49e23577..fe9e6dc4b799f58ea013743373dfd25320a06f8c 100644 (file)
@@ -2003,7 +2003,7 @@ MagickExport const char *GetImageProperty(const Image *image,
             image->properties);
           return(p);
         }
-      if (LocaleNCompare("fx:",property,3) != 0)
+      if (LocaleNCompare("fx:",property,3) != 0) /* NOT fx: !!!! */
         {
           p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
             image->properties,property);
@@ -2216,9 +2216,11 @@ static const char *GetMagickPropertyLetter(const ImageInfo *image_info,
       ConcatenateMagickString(value,"B",MaxTextExtent);
       break;
     }
-    case 'c':  /* image comment property */
+    case 'c':  /* image comment property - empty string by default */
     {
       string=GetImageProperty(image,"comment",exception);
+      if ( string == (const char *)NULL)
+        string="";
       break;
     }
     case 'd':  /* Directory component of filename */
@@ -2261,9 +2263,11 @@ static const char *GetMagickPropertyLetter(const ImageInfo *image_info,
             GetNumberColors(image,(FILE *) NULL,exception));
       break;
     }
-    case 'l': /* Image label  */
+    case 'l': /* Image label properity - empty string by default */
     {
       string=GetImageProperty(image,"label",exception);
+      if ( string == (const char *)NULL)
+        string="";
       break;
     }
     case 'm': /* Image format (file magick) */
@@ -2474,7 +2478,7 @@ static const char *GetMagickPropertyLetter(const ImageInfo *image_info,
   if (*value != '\0')
     string=value;
   if (string != (char *)NULL) {
-    (void) SetImageArtifact(image, "get-properity", value);
+    (void) SetImageArtifact(image, "get-properity", string);
     return(GetImageArtifact(image, "get-properity"));
   }
   return((char *)NULL);
@@ -2515,9 +2519,7 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
     {
       if (LocaleCompare("channels",property) == 0)
         {
-          /*
-            Image channels.
-          */
+          /* FUTURE: return actual image channels */
           (void) FormatLocaleString(value,MaxTextExtent,"%s",
             CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
             image->colorspace));
@@ -2531,9 +2533,7 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
           ColorspaceType
             colorspace;
 
-          /*
-            Image storage class and colorspace.
-          */
+          /* FUTURE: return actual colorspace - no 'gray' stuff */
           colorspace=image->colorspace;
           if( IfMagickTrue(IsImageGray(image,exception)) )
             colorspace=GRAYColorspace;
@@ -2838,7 +2838,7 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
   if (*value != '\0')
     string=value;
   if (string != (char *)NULL) {
-    (void) SetImageArtifact(image, "get-properity", value);
+    (void) SetImageArtifact(image, "get-properity", string);
     return(GetImageArtifact(image, "get-properity"));
   }
   return((char *)NULL);
@@ -3398,23 +3398,28 @@ MagickExport MagickBooleanType SetImageProperty(Image *image,
   if( IfMagickTrue(image->debug) )
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
 
+  /* Create splay-tree */
   if (image->properties == (void *) NULL)
     image->properties=NewSplayTree(CompareSplayTreeString,
       RelinquishMagickMemory,RelinquishMagickMemory);
-  if ((value == (const char *) NULL) || (*value == '\0'))
+
+  /* Delete properity if NULL --  empty string values are valid! */
+  if ((value == (const char *) NULL))
     return(DeleteImageProperty(image,property));
   status=MagickTrue;
 
+  /* Do not 'set' single letter properties - read only shorthand */
   if (strlen(property) <= 1)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
           OptionError,"SetReadOnlyProperty","'%s'",property);
       return(MagickFalse);
     }
+
   /* FUTURE: These should produce 'illegal settings'
-     + test for binary chars in name,
-     + first letter must be a alphabetic
-     + special prefix
+     + binary chars in p[roperty key
+     + single letter property keys (read only)
+     + known special prefix (read only, they don't get saved!)
   */
 
   switch (*property)