[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
andreas.kling at nokia.com
andreas.kling at nokia.com
Wed Dec 22 13:45:18 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit c6e3253b4bec11f0280c5c269df928147aa2a70e
Author: andreas.kling at nokia.com <andreas.kling at nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Sep 24 22:57:21 2010 +0000
2010-09-24 Andreas Kling <andreas.kling at nokia.com>
Reviewed by Dirk Schulze.
SVG: Make SVGLength's stringToLengthType() stricter and faster
https://bugs.webkit.org/show_bug.cgi?id=46066
Add test coverage for handling of invalid SVGLength units.
* svg/custom/invalid-length-units-expected.txt: Added.
* svg/custom/invalid-length-units.html: Added.
* svg/custom/script-tests/invalid-length-units.js: Added.
(trySettingLength):
2010-09-24 Andreas Kling <andreas.kling at nokia.com>
Reviewed by Dirk Schulze.
SVG: Make SVGLength's stringToLengthType() stricter and faster
https://bugs.webkit.org/show_bug.cgi?id=46066
Only accept unit names immediately following the numeric value.
This behavior matches Gecko.
Also, using String::endsWith("foo") caused a temporary WTF::String to be created.
Avoid this by comparing characters directly.
10.5% speedup on <http://data.xeoh.net/svg.benchmark/>
Test: svg/custom/invalid-length-units.html
* svg/SVGLength.cpp:
(WebCore::stringToLengthType):
(WebCore::SVGLength::setValueAsString):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68307 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 8bd8dcf..db9404c 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-24 Andreas Kling <andreas.kling at nokia.com>
+
+ Reviewed by Dirk Schulze.
+
+ SVG: Make SVGLength's stringToLengthType() stricter and faster
+ https://bugs.webkit.org/show_bug.cgi?id=46066
+
+ Add test coverage for handling of invalid SVGLength units.
+
+ * svg/custom/invalid-length-units-expected.txt: Added.
+ * svg/custom/invalid-length-units.html: Added.
+ * svg/custom/script-tests/invalid-length-units.js: Added.
+ (trySettingLength):
+
2010-09-24 Mihai Parparita <mihaip at chromium.org>
Reviewed by Adam Barth.
diff --git a/LayoutTests/svg/custom/invalid-length-units-expected.txt b/LayoutTests/svg/custom/invalid-length-units-expected.txt
new file mode 100644
index 0000000..7512ae1
--- /dev/null
+++ b/LayoutTests/svg/custom/invalid-length-units-expected.txt
@@ -0,0 +1,29 @@
+Tests handling of invalid SVG length units.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS rect.setAttribute('x', ''); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', ' '); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', 'foo'); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10foo'); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', 'px'); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10px '); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10% '); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10 % '); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10 %'); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10 px '); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10 px'); rect.x.baseVal.valueAsString is '0'
+PASS rect.setAttribute('x', '10'); rect.x.baseVal.valueAsString is '10'
+PASS rect.setAttribute('x', '10%'); rect.x.baseVal.valueAsString is '10%'
+PASS rect.setAttribute('x', '10em'); rect.x.baseVal.valueAsString is '10em'
+PASS rect.setAttribute('x', '10ex'); rect.x.baseVal.valueAsString is '10ex'
+PASS rect.setAttribute('x', '10px'); rect.x.baseVal.valueAsString is '10px'
+PASS rect.setAttribute('x', '10cm'); rect.x.baseVal.valueAsString is '10cm'
+PASS rect.setAttribute('x', '10mm'); rect.x.baseVal.valueAsString is '10mm'
+PASS rect.setAttribute('x', '10pt'); rect.x.baseVal.valueAsString is '10pt'
+PASS rect.setAttribute('x', '10pc'); rect.x.baseVal.valueAsString is '10pc'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/custom/invalid-length-units.html b/LayoutTests/svg/custom/invalid-length-units.html
new file mode 100644
index 0000000..489099c
--- /dev/null
+++ b/LayoutTests/svg/custom/invalid-length-units.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/invalid-length-units.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/svg/custom/script-tests/invalid-length-units.js b/LayoutTests/svg/custom/script-tests/invalid-length-units.js
new file mode 100644
index 0000000..c67f5c0
--- /dev/null
+++ b/LayoutTests/svg/custom/script-tests/invalid-length-units.js
@@ -0,0 +1,40 @@
+description("Tests handling of invalid SVG length units.");
+
+var svgNS = "http://www.w3.org/2000/svg";
+
+var svgRoot = document.createElementNS(svgNS, "svg");
+document.documentElement.appendChild(svgRoot);
+
+rect = document.createElementNS(svgNS, "rect");
+svgRoot.appendChild(rect);
+
+function trySettingLength(length, expected)
+{
+ rect.setAttribute('x', "1234");
+ shouldBe("rect.setAttribute('x', '" + length + "'); rect.x.baseVal.valueAsString", expected);
+}
+
+trySettingLength("", "'0'");
+trySettingLength(" ", "'0'");
+trySettingLength("foo", "'0'");
+trySettingLength("10foo", "'0'");
+trySettingLength("px", "'0'");
+trySettingLength("10px ", "'0'");
+trySettingLength("10% ", "'0'");
+trySettingLength("10 % ", "'0'");
+trySettingLength("10 %", "'0'");
+trySettingLength("10 px ", "'0'");
+trySettingLength("10 px", "'0'");
+trySettingLength("10", "'10'");
+trySettingLength("10%", "'10%'");
+trySettingLength("10em", "'10em'");
+trySettingLength("10ex", "'10ex'");
+trySettingLength("10px", "'10px'");
+trySettingLength("10cm", "'10cm'");
+trySettingLength("10mm", "'10mm'");
+trySettingLength("10pt", "'10pt'");
+trySettingLength("10pc", "'10pc'");
+
+document.documentElement.removeChild(svgRoot);
+
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 093f48d..3c3d7e4 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,24 @@
+2010-09-24 Andreas Kling <andreas.kling at nokia.com>
+
+ Reviewed by Dirk Schulze.
+
+ SVG: Make SVGLength's stringToLengthType() stricter and faster
+ https://bugs.webkit.org/show_bug.cgi?id=46066
+
+ Only accept unit names immediately following the numeric value.
+ This behavior matches Gecko.
+
+ Also, using String::endsWith("foo") caused a temporary WTF::String to be created.
+ Avoid this by comparing characters directly.
+
+ 10.5% speedup on <http://data.xeoh.net/svg.benchmark/>
+
+ Test: svg/custom/invalid-length-units.html
+
+ * svg/SVGLength.cpp:
+ (WebCore::stringToLengthType):
+ (WebCore::SVGLength::setValueAsString):
+
2010-09-24 Luiz Agostini <luiz.agostini at openbossa.org>
Reviewed by Kenneth Rohde Christiansen.
diff --git a/WebCore/svg/SVGLength.cpp b/WebCore/svg/SVGLength.cpp
index bdd5b27..a8cfb4e 100644
--- a/WebCore/svg/SVGLength.cpp
+++ b/WebCore/svg/SVGLength.cpp
@@ -86,28 +86,41 @@ static inline String lengthTypeToString(SVGLengthType type)
return String();
}
-inline SVGLengthType stringToLengthType(const String& string)
+inline SVGLengthType stringToLengthType(const UChar*& ptr, const UChar* end)
{
- if (string.endsWith("%"))
- return LengthTypePercentage;
- else if (string.endsWith("em"))
+ if (ptr == end)
+ return LengthTypeNumber;
+
+ const UChar firstChar = *ptr;
+ ++ptr;
+
+ if (firstChar == '%') {
+ if (ptr == end)
+ return LengthTypePercentage;
+ return LengthTypeUnknown;
+ }
+
+ const UChar secondChar = *ptr;
+
+ if (++ptr != end)
+ return LengthTypeUnknown;
+
+ if (firstChar == 'e' && secondChar == 'm')
return LengthTypeEMS;
- else if (string.endsWith("ex"))
+ if (firstChar == 'e' && secondChar == 'x')
return LengthTypeEXS;
- else if (string.endsWith("px"))
+ if (firstChar == 'p' && secondChar == 'x')
return LengthTypePX;
- else if (string.endsWith("cm"))
+ if (firstChar == 'c' && secondChar == 'm')
return LengthTypeCM;
- else if (string.endsWith("mm"))
+ if (firstChar == 'm' && secondChar == 'm')
return LengthTypeMM;
- else if (string.endsWith("in"))
+ if (firstChar == 'i' && secondChar == 'n')
return LengthTypeIN;
- else if (string.endsWith("pt"))
+ if (firstChar == 'p' && secondChar == 't')
return LengthTypePT;
- else if (string.endsWith("pc"))
+ if (firstChar == 'p' && secondChar == 'c')
return LengthTypePC;
- else if (!string.isEmpty())
- return LengthTypeNumber;
return LengthTypeUnknown;
}
@@ -260,8 +273,8 @@ bool SVGLength::setValueAsString(const String& s)
if (!parseNumber(ptr, end, convertedNumber, false))
return false;
- SVGLengthType type = stringToLengthType(s);
- if (ptr != end && type == LengthTypeNumber)
+ SVGLengthType type = stringToLengthType(ptr, end);
+ if (type == LengthTypeUnknown)
return false;
m_unit = storeUnit(extractMode(m_unit), type);
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list