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

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

Issue 1642463004: Extended error reporting for SVG path parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "path flag" -> "arc flag" Created 4 years, 11 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/SVGPathStringSource.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGPathStringSource.cpp b/third_party/WebKit/Source/core/svg/SVGPathStringSource.cpp
index 83d46db491f0d3c6da97996afdabcf12e6ecc6ce..9a0142dcbf25fdbb79690877d598fe8f4866df24 100644
--- a/third_party/WebKit/Source/core/svg/SVGPathStringSource.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGPathStringSource.cpp
@@ -26,10 +26,9 @@
namespace blink {
SVGPathStringSource::SVGPathStringSource(const String& string)
- : m_string(string)
- , m_is8BitSource(string.is8Bit())
- , m_seenError(false)
+ : m_is8BitSource(string.is8Bit())
, m_previousCommand(PathSegUnknown)
+ , m_string(string)
{
ASSERT(!string.isNull());
@@ -124,23 +123,39 @@ static bool nextCommandHelper(unsigned lookahead, SVGPathSegType previousCommand
return false;
}
+void SVGPathStringSource::setErrorMark(SVGParseStatus status)
+{
+ if (m_error.status() != SVGParseStatus::NoError)
+ return;
+ size_t locus = m_is8BitSource
+ ? m_current.m_character8 - m_string.characters8()
+ : m_current.m_character16 - m_string.characters16();
+ m_error = SVGParsingError(status, locus);
+}
+
float SVGPathStringSource::parseNumberWithError()
{
float numberValue = 0;
+ bool error;
if (m_is8BitSource)
- m_seenError |= !parseNumber(m_current.m_character8, m_end.m_character8, numberValue);
+ error = !parseNumber(m_current.m_character8, m_end.m_character8, numberValue);
else
- m_seenError |= !parseNumber(m_current.m_character16, m_end.m_character16, numberValue);
+ error = !parseNumber(m_current.m_character16, m_end.m_character16, numberValue);
+ if (UNLIKELY(error))
+ setErrorMark(SVGParseStatus::ExpectedNumber);
return numberValue;
}
bool SVGPathStringSource::parseArcFlagWithError()
{
bool flagValue = false;
+ bool error;
if (m_is8BitSource)
- m_seenError |= !parseArcFlag(m_current.m_character8, m_end.m_character8, flagValue);
+ error = !parseArcFlag(m_current.m_character8, m_end.m_character8, flagValue);
else
- m_seenError |= !parseArcFlag(m_current.m_character16, m_end.m_character16, flagValue);
+ error = !parseArcFlag(m_current.m_character16, m_end.m_character16, flagValue);
+ if (UNLIKELY(error))
+ setErrorMark(SVGParseStatus::ExpectedArcFlag);
return flagValue;
}
@@ -149,7 +164,14 @@ SVGPathSegType SVGPathStringSource::peekSegmentType()
ASSERT(hasMoreData());
// This won't work in all cases because of the state required to "detect" implicit commands.
unsigned lookahead = m_is8BitSource ? *m_current.m_character8 : *m_current.m_character16;
- return parseSVGSegmentTypeHelper(lookahead);
+ SVGPathSegType segmentType = parseSVGSegmentTypeHelper(lookahead);
+ // Here we assume that this is only called via SVGPathParser::initialCommandIsMoveTo.
+ // TODO(fs): It ought to be possible to refactor away this entirely, and
+ // just handle this in parseSegment (which we sort of do already...) The
+ // only user is the method mentioned above.
+ if (segmentType != PathSegMoveToAbs && segmentType != PathSegMoveToRel)
+ setErrorMark(SVGParseStatus::ExpectedMoveToCommand);
+ return segmentType;
}
PathSegmentData SVGPathStringSource::parseSegment()
@@ -160,10 +182,14 @@ PathSegmentData SVGPathStringSource::parseSegment()
SVGPathSegType command = parseSVGSegmentTypeHelper(lookahead);
if (command == PathSegUnknown) {
// Possibly an implicit command. Not allowed if this is the first command.
- if (m_previousCommand == PathSegUnknown)
+ if (m_previousCommand == PathSegUnknown) {
+ setErrorMark(SVGParseStatus::ExpectedMoveToCommand);
return segment;
- if (!nextCommandHelper(lookahead, m_previousCommand, command))
+ }
+ if (!nextCommandHelper(lookahead, m_previousCommand, command)) {
+ setErrorMark(SVGParseStatus::ExpectedPathCommand);
return segment;
+ }
} else {
// Valid explicit command.
if (m_is8BitSource)
@@ -174,7 +200,7 @@ PathSegmentData SVGPathStringSource::parseSegment()
segment.command = m_previousCommand = command;
- ASSERT(!m_seenError);
+ ASSERT(m_error.status() == SVGParseStatus::NoError);
switch (segment.command) {
case PathSegCurveToCubicRel:
@@ -228,7 +254,7 @@ PathSegmentData SVGPathStringSource::parseSegment()
ASSERT_NOT_REACHED();
}
- if (UNLIKELY(m_seenError))
+ if (UNLIKELY(m_error.status() != SVGParseStatus::NoError))
segment.command = PathSegUnknown;
return segment;
}
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGPathStringSource.h ('k') | third_party/WebKit/Source/core/svg/SVGPathUtilities.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698