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

Unified Diff: third_party/WebKit/Source/core/svg/SVGNumber.cpp

Issue 1667353003: Error reporting for number-or-percentage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
Index: third_party/WebKit/Source/core/svg/SVGNumber.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGNumber.cpp b/third_party/WebKit/Source/core/svg/SVGNumber.cpp
index d652046cbfc9542ee66eed9351a648b22375c818..2b0d97f0dcd90691a38c2944f7bf6046067b079a 100644
--- a/third_party/WebKit/Source/core/svg/SVGNumber.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGNumber.cpp
@@ -106,13 +106,42 @@ PassRefPtrWillBeRawPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const
return create(m_value);
}
-SVGParsingError SVGNumberAcceptPercentage::setValueAsString(const String& string)
+template<typename CharType>
+static SVGParsingError parseNumberOrPercentage(const CharType*& ptr, const CharType* end, float& number)
{
- if (parseNumberOrPercentage(string, m_value))
- return SVGParseStatus::NoError;
+ const CharType* start = ptr;
+ if (!parseNumber(ptr, end, number, AllowLeadingWhitespace))
+ return SVGParsingError(SVGParseStatus::ExpectedNumberOrPercentage, ptr - start);
+ if (ptr < end && *ptr == '%') {
+ number /= 100;
+ ptr++;
+ }
+ if (skipOptionalSVGSpaces(ptr, end))
+ return SVGParsingError(SVGParseStatus::TrailingGarbage, ptr - start);
+ return SVGParseStatus::NoError;
+}
+SVGParsingError SVGNumberAcceptPercentage::setValueAsString(const String& string)
+{
m_value = 0;
- return SVGParseStatus::ParsingFailed;
+
+ if (string.isEmpty())
+ return SVGParseStatus::ExpectedNumberOrPercentage;
+
+ float number = 0;
+ SVGParsingError error;
+ if (string.is8Bit()) {
+ const LChar* ptr = string.characters8();
+ const LChar* end = ptr + string.length();
+ error = parseNumberOrPercentage(ptr, end, number);
+ } else {
+ const UChar* ptr = string.characters16();
+ const UChar* end = ptr + string.length();
+ error = parseNumberOrPercentage(ptr, end, number);
+ }
+ if (error == SVGParseStatus::NoError)
+ m_value = number;
+ return error;
}
SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value)
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | third_party/WebKit/Source/core/svg/SVGParserUtilities.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698