SVG elements cannot have spaces before attribute values




11 years ago
11 years ago


(Reporter: cyberknight, Unassigned)


Firefox Tracking Flags

(Not tracked)




11 years ago
User-Agent:       Opera/9.52 (Windows NT 5.1; U; en)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0

The elements of an SVG image cannot have spaces before the values of their attributes, or else Firefox will completely ignore them. For example, it renders the elements correctly for cx="100px", but will simply ignore a cx="  100px" attribute. The problem occurs with all elements ("circle", "rect" etc.), with any numeric attribute, but not with alphanumeric attributes (like "style", for example, which parses correctly the values).

Reproducible: Always

Steps to Reproduce:
1. Create an SVG file with some elements, e.g., three circles:

<svg  xmlns=""><g>
  <circle cx="100" cy="100" r="50" style="fill:red"/>
  <circle cx="150" cy="150" r="50" style="fill:green"/>
  <circle cx="200" cy="200" r="50" style="fill:blue"/>

Opening the file in Firefox will render three circles, aligned correctly.

2. Now add one space before, say, the green circle's cx attribute's value and save the SVG file:

<svg  xmlns=""><g>
  <circle cx="100" cy="100" r="50" style="fill:red"/>
  <circle cx=" 150" cy="150" r="50" style="fill:green"/>
  <circle cx="200" cy="200" r="50" style="fill:blue"/>

3. Reload the image. The red and the blue circles are still on the same places, but the green one is set at (0,150), that is, the cx attribute is assumed as zero (or, otherwise, it is ignored, so the default zero is used).
Actual Results:  
All SVG files with spaces before any numeric attribute are incorrectly rendered. When people edit SVG files by hand, it's natural to add spaces to tabulate a series of similar or correlated elements or even by mistake, like this:

  <rect x="100" y="100" width="1000" height="50" style="fill:blue"/>
  <rect x="100" y="100" width=" 100" height="50" style="fill:green"/>
  <rect x="100" y="100" width="  10" height="50" style="fill:red"/>

Sooner or later, people will stumble on an SVG image with a space before an attribute and it will render oddly on Firefox...

Expected Results:  
Firefox should completely ignore spaces before numeric values passed to attributes of SVG elements.

Opera renders SVG with spaces before numeric values correctly. It took me some time to realize that it was a bug in Firefox, not a problem with my hand-written SVG files.
This is invalid. Spaces are not allowed per the specification. 

I guess you should raise a bug on Opera since it is not doing the right thing.

Last Resolved: 11 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 404089
You need to log in before you can comment on or make changes to this bug.