From a459d629c1e4ea3e18c3480021e9ea0b32629ab3 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Tue, 17 Apr 2018 19:05:52 +0000 Subject: [PATCH] removeDefaultAttributeValue: Special-case order attribute Scour tried to handle "order" attribute as a SVGLength. However, the "order" attribute *can* consist of two integers according to the [SVG 1.1 Specification] and SVGLength is not designed to handle that. With this change, we now pretend that "order" is a string, which side steps this issue. [SVG 1.1 Specification]: https://www.w3.org/TR/SVG11/single-page.html#filters-feConvolveMatrixElementOrderAttribute Closes: #189 Signed-off-by: Niels Thykier --- scour/scour.py | 7 ++++++- testscour.py | 10 ++++++++++ unittests/remove-default-attr-order.svg | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 unittests/remove-default-attr-order.svg diff --git a/scour/scour.py b/scour/scour.py index c6f4c75..e5346b8 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1848,7 +1848,12 @@ default_attributes = [ DefaultAttribute('offset', 0, elements=['feFuncA', 'feFuncB', 'feFuncG', 'feFuncR']), DefaultAttribute('operator', 'over', elements=['feComposite']), DefaultAttribute('operator', 'erode', elements=['feMorphology']), - DefaultAttribute('order', 3, elements=['feConvolveMatrix']), + # We pretend order is a string (because handling it as an + # SVGLength will cause issues when order is two integers). Note + # that order must be exactly one or two integers (no units or + # fancy numbers), so working with it a string will generally just + # work. + DefaultAttribute('order', '3', elements=['feConvolveMatrix']), DefaultAttribute('pointsAtX', 0, elements=['feSpotLight']), DefaultAttribute('pointsAtY', 0, elements=['feSpotLight']), DefaultAttribute('pointsAtZ', 0, elements=['feSpotLight']), diff --git a/testscour.py b/testscour.py index b52d98f..2c25258 100755 --- a/testscour.py +++ b/testscour.py @@ -1570,6 +1570,16 @@ class RemoveDefaultGradFYValue(unittest.TestCase): 'fy matching cy not removed') +class RemoveDefaultAttributeOrderSVGLengthCrash(unittest.TestCase): + + # Triggered a crash in v0.36 + def runTest(self): + try: + scourXmlFile('unittests/remove-default-attr-order.svg') + except AttributeError: + self.fail("Processing the order attribute triggered an AttributeError ") + + class CDATAInXml(unittest.TestCase): def runTest(self): diff --git a/unittests/remove-default-attr-order.svg b/unittests/remove-default-attr-order.svg new file mode 100644 index 0000000..d65848a --- /dev/null +++ b/unittests/remove-default-attr-order.svg @@ -0,0 +1,11 @@ + + + + + + + + + +