Closed Bug 386416 Opened 17 years ago Closed 17 years ago

SVG: order attribute of feConvolveMatrix does not accept comma separated integers

Categories

(Core :: SVG, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: no-reply-address-of-florian, Assigned: longsonr)

References

()

Details

Attachments

(3 files, 6 obsolete files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a6pre) Gecko/20070629 Minefield/3.0a6pre
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a6pre) Gecko/20070629 Minefield/3.0a6pre

The feConvolveMatrix will not be displayed if the order attribute has a value like "3,3" or "1,10".

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
Component: General → SVG
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → Trunk
It does accept 2 integers, it just doesn't like the comma between them at the moment.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached patch patch (obsolete) — Splinter Review
Assignee: nobody → longsonr
Status: NEW → ASSIGNED
Attachment #270485 - Flags: superreview?(tor)
Attachment #270485 - Flags: review?(tor)
Possible ways how to write a List in SVG documents is explained here:
http://www.w3.org/TR/SVG11/types.html#DataTypeList
Attached image A SVG file for testing the patch. (obsolete) —
(In reply to comment #4)
> Created an attachment (id=270487) [details]
> A SVG file for testing the patch.
> 

url(#filter3) refers to something that does not exist.

(In reply to comment #5)
> Created an attachment (id=270488) [details]
> A SVG file with a incorrrect list. (two commas instead of one)
> 

This would parse OK with the patch which is wrong but then pretty much all of the svg number list processing suffers from this fault.

(In reply to comment #6)
> Created an attachment (id=270489) [details]
> A second SVG file with a incorrrect list. (two whitespaces before the comma)
> 

There is nothing wrong with this.

(In reply to comment #7)
> (In reply to comment #4)
> > Created an attachment (id=270487) [details] [details]
> > A SVG file for testing the patch.
> > 
> 
> url(#filter3) refers to something that does not exist.
One of the filters has a wrong id, I will submit a corrected version.

> 
> (In reply to comment #5)
> > Created an attachment (id=270488) [details] [details]
> > A SVG file with a incorrrect list. (two commas instead of one)
> > 
> 
> This would parse OK with the patch which is wrong but then pretty much all of
> the svg number list processing suffers from this fault.
Well you the Mozilla SVG developers have do decide this by your own. It would be nice if you at least start from now on to use/write some kind of pharseSVGIntList function.


> 
> (In reply to comment #6)
> > Created an attachment (id=270489) [details] [details]
> > A second SVG file with a incorrrect list. (two whitespaces before the comma)
> > 
> 
> There is nothing wrong with this.
> 
Year, my mistake, I overlooked the +. It is wrong that the example is wrong.

Attachment #270487 - Attachment is obsolete: true
Attachment #270489 - Attachment is obsolete: true
(In reply to comment #8)
> > This would parse OK with the patch which is wrong but then pretty much all of
> > the svg number list processing suffers from this fault.
> Well you the Mozilla SVG developers have do decide this by your own. It would
> be nice if you at least start from now on to use/write some kind of
> pharseSVGIntList function.
> 

Do feel free to raise another bug about this so we remember to tackle it as a follow up.
Comment on attachment 270485 [details] [diff] [review]
patch

It seems that this new version would allow invalid strings like "4,,5".  Also appears that case of only one value won't be handled correctly (setting output for both to that value).

Can nsAutoPtr be used to manage the string?
Attachment #270485 - Flags: superreview?(tor)
Attachment #270485 - Flags: superreview-
Attachment #270485 - Flags: review?(tor)
Attachment #270485 - Flags: review-
Summary: SVG: order attribute of feConvolveMatrix does not accept two integers → SVG: order attribute of feConvolveMatrix does not accept comma separated integers
Flags: blocking1.9+
Attached patch updated patch (obsolete) — Splinter Review
No string management required with this version.
Attachment #270485 - Attachment is obsolete: true
Attachment #284472 - Flags: review?(tor)
Comment on attachment 284472 [details] [diff] [review]
updated patch

>+PRBool
>+nsSVGElement::ParseNumberOptionalNumber(nsIAtom* aAttribute, const nsAString& aValue,
>+                                        nsSVGNumber2* aNum1, nsSVGNumber2* aNum2, 
>+                                        float defaultValue1, float defaultValue2)
>+{
>+  char *rest;
>+  PRBool parseError = PR_FALSE;
>+
>+  NS_ConvertUTF16toUTF8 value(aValue);
>+  value.CompressWhitespace(PR_FALSE, PR_TRUE);
>+  const char *str = value.get();
>+
>+  float x = static_cast<float>(PR_strtod(str, &rest));
>+  float y = defaultValue2;
>+
>+  if (str == rest) {
>+    //first value was illformed
>+    parseError = PR_TRUE;
>+  } else {
>+    if (*rest == '\0') {
>+      //second value was not supplied
>+      y = x;
>+    } else {

>+      for (PRBool commaFound = PR_FALSE;
>+           *rest == ',' || NS_IsAsciiWhitespace(*rest); ++rest) {
>+        if (*rest == ',') {
>+          if (commaFound)
>+            break;
>+          commaFound = PR_TRUE;
>+          continue;
>+        }
>+      }

Would this be slightly simpler?

while (NS_IsAsciiWhitespace(*rest))
  rest++;
if (*rest == ',')
  rest++;

>+      y = static_cast<float>(PR_strtod(rest, &rest));
>+      if (*rest != '\0') {
>+        //second value was illformed or there was trailing content
>+        parseError = PR_TRUE;
>+      }
>+    }
>+  }
>+
>+  if (parseError) {
>+    ReportAttributeParseFailure(GetOwnerDoc(), aAttribute, aValue);
>+    x = defaultValue1;
>+    y = defaultValue2;
>+  }
>+
>+  aNum1->SetBaseValue(x, this, PR_FALSE);
>+  aNum2->SetBaseValue(y, this, PR_FALSE);
>+
>+  return (!parseError);
>+}
Comment on attachment 284472 [details] [diff] [review]
updated patch

> PRBool
> nsSVGFEGaussianBlurElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
>                                            const nsAString& aValue,
>                                            nsAttrValue& aResult)
> {
>   if (aName == nsGkAtoms::stdDeviation && aNameSpaceID == kNameSpaceID_None) {
>-    return ScanDualValueAttribute(aValue, nsGkAtoms::stdDeviation,
>+    if (ParseNumberOptionalNumber(aName, aValue,
>                                   &mNumberAttributes[STD_DEV_X],
>                                   &mNumberAttributes[STD_DEV_Y],
>-                                  &sNumberInfo[STD_DEV_X],
>-                                  &sNumberInfo[STD_DEV_Y],
>-                                  aResult);
>+                                  sNumberInfo[STD_DEV_X].mDefaultValue,
>+                                  sNumberInfo[STD_DEV_Y].mDefaultValue)) {
>+      aResult.SetTo(aValue);
>+      return PR_TRUE;
>+    }
>+    return PR_TRUE;
>   }
>   return nsSVGFEGaussianBlurElementBase::ParseAttribute(aNameSpaceID, aName,
>                                                         aValue, aResult);
> }

Used for example, though all the ParseAttribute implementations in the patch share the same basic structure.  This is only setting aResult for a successful parse of the attribute, which means that if someone tries to set a garbage value and then read it back with getAttribute, the value returned will be the previous value.  If you change the second PR_TRUE to PR_FALSE, nsGenericElement::SetAttr will do the SetTo for you.
Strictly speaking, the SVG specification forbids leading whitespace for lists (of which "xxx optional xxx" is a special case).  Your patch will accept a string of that type.

(In reply to comment #15)
> Strictly speaking, the SVG specification forbids leading whitespace for lists
> (of which "xxx optional xxx" is a special case).  Your patch will accept a
> string of that type.

Likewise for trailing whitespace.

Valid:

"3 4"
"3,4"
"3 ,4"
"3 , 4"

Invalid:

" 3,4"
"3,4 "

http://www.w3.org/TR/SVG11/types.html#DataTypeList

Attached patch address review comments (obsolete) — Splinter Review
Attachment #284472 - Attachment is obsolete: true
Attachment #284617 - Flags: review?(tor)
Attachment #284472 - Flags: review?(tor)
Comment on attachment 284617 [details] [diff] [review]
address review comments

>+PRBool
>+nsSVGElement::ParseNumberOptionalNumber(nsIAtom* aAttribute, const nsAString& aValue,
>+                                        nsSVGNumber2* aNum1, nsSVGNumber2* aNum2, 
>+                                        float defaultValue1, float defaultValue2)
>+{
>+  NS_ConvertUTF16toUTF8 value(aValue);
>+  const char *str = value.get();
>+
>+  PRBool parseError = NS_IsAsciiWhitespace(*str);

Shouldn't everything below up to the parseError test be in a "if (!parseError)"?

>+  char *rest;
>+  float x = static_cast<float>(PR_strtod(str, &rest));
>+  float y = x;
>+
>+  if (str == rest) {
>+    //first value was illformed
>+    parseError = PR_TRUE;
>+  } else {
>+    if (*rest != '\0') {
>+      while (NS_IsAsciiWhitespace(*rest)) {
>+        ++rest;
>+      }
>+      if (*rest == ',') {
>+        ++rest;
>+      }
>+
>+      y = static_cast<float>(PR_strtod(rest, &rest));
>+      if (*rest != '\0') {
>+        //second value was illformed or there was trailing content
>+        parseError = PR_TRUE;
>+      }
>+    }
>+  }

>+  if (parseError) {
>+    ReportAttributeParseFailure(GetOwnerDoc(), aAttribute, aValue);
>+    x = defaultValue1;
>+    y = defaultValue2;
>+  }

If you add nsAttrValue to the parameters and a "else aResult.SetTo(aValue);" you can avoid that code at all the call sites and instead just do "return Parse...".

>+  aNum1->SetBaseValue(x, this, PR_FALSE);
>+  aNum2->SetBaseValue(y, this, PR_FALSE);
>+
>+  return (!parseError);
>+}
(In reply to comment #18)
> >+  PRBool parseError = NS_IsAsciiWhitespace(*str);
> 
> Shouldn't everything below up to the parseError test be in a "if
> (!parseError)"?

Sure, if you want. The common valid case is fractionally slower the uncommon invalid case is faster. Functionally the same outcome.

> If you add nsAttrValue to the parameters and a "else aResult.SetTo(aValue);"
> you can avoid that code at all the call sites and instead just do "return
> Parse...".
> 

Done.
Attachment #284617 - Attachment is obsolete: true
Attachment #284643 - Flags: review?(tor)
Attachment #284617 - Flags: review?(tor)
Attachment #284643 - Flags: review?(tor) → review+
Attachment #284643 - Flags: superreview?(roc)
+    x = y = static_cast<float>(PR_strtod(str, &rest));

Use constructor casts to cast to float.

What if the Parse* functions just took the indexes of the number-attributes and integer-attributes instead of pointers to nsSVGNumber and nsSVGInteger? Then they could look up the correct default value, saving two parameters and reducing code in callers.
Attachment #284643 - Attachment is obsolete: true
Attachment #284698 - Flags: superreview?(roc)
Attachment #284643 - Flags: superreview?(roc)
Attachment #284698 - Flags: superreview?(roc) → superreview+
checked in.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: