Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Unified Diff: Source/core/svg/SVGLength.cpp

Issue 302643004: [SVG2] Allow leading and trailing whitespace in svg attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@relax_todouble_wtf
Patch Set: split tests to combat slow xp trybots Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/svg/SVGInteger.cpp ('k') | Source/core/svg/SVGLengthList.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGLength.cpp
diff --git a/Source/core/svg/SVGLength.cpp b/Source/core/svg/SVGLength.cpp
index 0fe1202a1c2e4d68acaa361060d8a8b5352a8c0c..ba4e00306833d07a117847440b29f4394ab0d009 100644
--- a/Source/core/svg/SVGLength.cpp
+++ b/Source/core/svg/SVGLength.cpp
@@ -73,32 +73,41 @@ SVGLengthType stringToLengthType(const CharType*& ptr, const CharType* end)
if (ptr == end)
return LengthTypeNumber;
- const UChar firstChar = *ptr;
-
- if (++ptr == end)
- return firstChar == '%' ? LengthTypePercentage : LengthTypeUnknown;
-
- const UChar secondChar = *ptr;
-
- if (++ptr != end)
- return LengthTypeUnknown;
-
- if (firstChar == 'e' && secondChar == 'm')
- return LengthTypeEMS;
- if (firstChar == 'e' && secondChar == 'x')
- return LengthTypeEXS;
- if (firstChar == 'p' && secondChar == 'x')
- return LengthTypePX;
- if (firstChar == 'c' && secondChar == 'm')
- return LengthTypeCM;
- if (firstChar == 'm' && secondChar == 'm')
- return LengthTypeMM;
- if (firstChar == 'i' && secondChar == 'n')
- return LengthTypeIN;
- if (firstChar == 'p' && secondChar == 't')
- return LengthTypePT;
- if (firstChar == 'p' && secondChar == 'c')
- return LengthTypePC;
+ SVGLengthType type = LengthTypeUnknown;
+ const CharType firstChar = *ptr++;
+
+ if (firstChar == '%') {
+ type = LengthTypePercentage;
+ } else if (isHTMLSpace<CharType>(firstChar)) {
+ type = LengthTypeNumber;
+ } else if (ptr < end) {
+ const CharType secondChar = *ptr++;
+
+ if (firstChar == 'p') {
+ if (secondChar == 'x')
+ type = LengthTypePX;
+ if (secondChar == 't')
+ type = LengthTypePT;
+ if (secondChar == 'c')
+ type = LengthTypePC;
+ } else if (firstChar == 'e') {
+ if (secondChar == 'm')
+ type = LengthTypeEMS;
+ if (secondChar == 'x')
+ type = LengthTypeEXS;
+ } else if (firstChar == 'c' && secondChar == 'm') {
+ type = LengthTypeCM;
+ } else if (firstChar == 'm' && secondChar == 'm') {
+ type = LengthTypeMM;
+ } else if (firstChar == 'i' && secondChar == 'n') {
+ type = LengthTypeIN;
+ } else if (isHTMLSpace<CharType>(firstChar) && isHTMLSpace<CharType>(secondChar)) {
+ type = LengthTypeNumber;
+ }
+ }
+
+ if (!skipOptionalSVGSpaces(ptr, end))
+ return type;
return LengthTypeUnknown;
}
@@ -189,7 +198,7 @@ static bool parseValueInternal(const String& string, float& convertedNumber, SVG
const CharType* ptr = string.getCharacters<CharType>();
const CharType* end = ptr + string.length();
- if (!parseNumber(ptr, end, convertedNumber, false))
+ if (!parseNumber(ptr, end, convertedNumber, AllowLeadingWhitespace))
return false;
type = stringToLengthType(ptr, end);
« no previous file with comments | « Source/core/svg/SVGInteger.cpp ('k') | Source/core/svg/SVGLengthList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698