SVG icon indicating copy to clipboard operation
SVG copied to clipboard

Crash/Exception due to invalid CSS parsing

Open dedmen opened this issue 4 years ago • 3 comments

Description

Given SVG input file with CSS polyline{ fill: none; }; ellipse{ stroke:url(#colorForest); fill: none; stroke-width: 4; }; This code https://github.com/svg-net/SVG/blob/master/Source/SvgDocument.cs#L490 parses the CSS and returns 3! rules, even though there are only two. First rule the polyline Second rule the ellipse Third rule Selector null and Value null, triggering a null reference exception at: rule.Selector https://github.com/svg-net/SVG/blob/master/Source/SvgDocument.cs#L499

Using this CSS: polyline{ fill: none; }; ellipse{ stroke:url(#colorForest); fill: none; stroke-width: 4; } Fixes the issue. Its technically a problem with the ExCSS parser thing, and not SVG itself.

Example data

townNames.txt

Used Versions

Running at commit c4e83167c6adfb8d6770eb109d1a03dd656096c2 from 20th jan 2021

dedmen avatar Apr 04 '21 01:04 dedmen

@dedmen

What do you expect from this issue ?

Please specify the correct CSS as below.

polyline{ fill: none; } ellipse{ stroke:url(#colorForest); fill: none; stroke-width: 4; }

H1Gdev avatar Apr 05 '21 01:04 H1Gdev

Now: Input: polyline{ fill: none; }; ellipse{ stroke:url(#colorForest); fill: none; stroke-width: 4; }; Output: 1 rule for polyline, 1 rule for ellipse, 1 rule for null

Input: polyline{ fill: none; }; ellipse{ stroke:url(#colorForest); fill: none; stroke-width: 4; } Output: 1 rule for polyline, 1 rule for ellipse

Expected:

Input: polyline{ fill: none; }; ellipse{ stroke:url(#colorForest); fill: none; stroke-width: 4; }; Output: 1 rule for polyline, 1 rule for ellipse

Input: polyline{ fill: none; }; ellipse{ stroke:url(#colorForest); fill: none; stroke-width: 4; } Output: 1 rule for polyline, 1 rule for ellipse

The semicolon at the end shouldn't cause the CSS parser to output a null rule, and trigger a NullReferenceException

dedmen avatar Apr 05 '21 17:04 dedmen

Fixes the issue. Its technically a problem with the ExCSS parser thing, and not SVG itself.

As you said, it depends on behavior of ExCSS library.

However, even major browsers(Edge, Firefox, Chrome) make an error for this semicolon issue. (sample HTML)

<html>
<meta charset="UTF-8">
<head>
<style type="text/css">
p {line-height:1.5;};
p {color:blue;}
</style>
</head>
<body>
<p>This is CSS test.</p>
</body>
</html>

For reference, the latest ExCSS gives the following results. Output: 1 rule for polyline

H1Gdev avatar Apr 05 '21 22:04 H1Gdev