From 48f9a70c2820e2e3c10fd001bdd9ac3f9e792c4b Mon Sep 17 00:00:00 2001 From: Robert Longson Date: Thu, 8 Apr 2010 09:58:04 +0100 Subject: [PATCH] Bug 553905 - data parser should parse up to a failure and not scrap the whole path. r=jwatt --- content/svg/content/src/nsSVGDataParser.cpp | 14 +++----------- content/svg/content/src/nsSVGDataParser.h | 2 +- content/svg/content/src/nsSVGPathDataParser.cpp | 10 +++------- content/svg/content/src/nsSVGPathDataParser.h | 6 +++--- content/svg/content/src/nsSVGPathElement.cpp | 5 ++++- content/svg/content/src/nsSVGPathSegList.cpp | 4 +--- content/svg/content/src/nsSVGTransformList.cpp | 4 +--- .../svg/content/src/nsSVGTransformListParser.h | 2 +- layout/reftests/svg/path-02.svg | 15 +++++++++++++++ layout/reftests/svg/reftest.list | 1 + 10 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 layout/reftests/svg/path-02.svg diff --git a/content/svg/content/src/nsSVGDataParser.cpp b/content/svg/content/src/nsSVGDataParser.cpp index 5fee495861c..04fa5767b74 100644 --- a/content/svg/content/src/nsSVGDataParser.cpp +++ b/content/svg/content/src/nsSVGDataParser.cpp @@ -61,8 +61,6 @@ nsresult nsSVGDataParser::Parse(const nsAString &aValue) { - nsresult rv = NS_OK; - char *str = ToNewUTF8String(aValue); if (!str) return NS_ERROR_OUT_OF_MEMORY; @@ -70,7 +68,7 @@ nsSVGDataParser::Parse(const nsAString &aValue) mInputPos = str; GetNextToken(); - rv = Match(); + nsresult rv = Match(); if (mTokenType != END) rv = NS_ERROR_FAILURE; // not all tokens were consumed @@ -85,8 +83,8 @@ nsSVGDataParser::Parse(const nsAString &aValue) void nsSVGDataParser::GetNextToken() { - mTokenPos = mInputPos; - mTokenVal = *mInputPos; + mTokenPos = mInputPos; + mTokenVal = *mInputPos; switch (mTokenVal) { case '0': case '1': case '2': case '3': case '4': @@ -129,12 +127,6 @@ void nsSVGDataParser::RewindTo(const char* aPos) GetNextToken(); } - -nsresult nsSVGDataParser::Match() -{ - return NS_OK; -} - //---------------------------------------------------------------------- nsresult nsSVGDataParser::MatchNonNegativeNumber(float* aX) diff --git a/content/svg/content/src/nsSVGDataParser.h b/content/svg/content/src/nsSVGDataParser.h index 7140556b454..6591db7e0f5 100644 --- a/content/svg/content/src/nsSVGDataParser.h +++ b/content/svg/content/src/nsSVGDataParser.h @@ -63,7 +63,7 @@ protected: // helpers void GetNextToken(); void RewindTo(const char* aPos); - virtual nsresult Match(); + virtual nsresult Match()=0; nsresult MatchNonNegativeNumber(float* aX); PRBool IsTokenNonNegativeNumberStarter(); diff --git a/content/svg/content/src/nsSVGPathDataParser.cpp b/content/svg/content/src/nsSVGPathDataParser.cpp index d2d6bfe0362..2da5a85cab3 100644 --- a/content/svg/content/src/nsSVGPathDataParser.cpp +++ b/content/svg/content/src/nsSVGPathDataParser.cpp @@ -878,10 +878,8 @@ nsSVGPathDataParserToInternal::Parse(const nsAString &aValue) mPrevSeg = nsIDOMSVGPathSeg::PATHSEG_UNKNOWN; nsresult rv = nsSVGPathDataParser::Parse(aValue); - NS_ENSURE_SUCCESS(rv, rv); - rv = PathFini(); - NS_ENSURE_SUCCESS(rv, rv); + PathFini(); return rv; } @@ -1214,7 +1212,7 @@ nsSVGPathDataParserToInternal::PathClose() return NS_OK; } -nsresult +void nsSVGPathDataParserToInternal::PathFini() { // We're done adding data to the arrays - copy to a straight array @@ -1226,7 +1224,7 @@ nsSVGPathDataParserToInternal::PathFini() argArraySize = mArguments.Length() * sizeof(float); mPathData->mArguments = (float *)malloc(argArraySize + mCommands.Length()); if (!mPathData->mArguments) - return NS_ERROR_OUT_OF_MEMORY; + return; memcpy(mPathData->mArguments, mArguments.Elements(), argArraySize); memcpy(mPathData->mArguments + mNumArguments, @@ -1234,8 +1232,6 @@ nsSVGPathDataParserToInternal::PathFini() mCommands.Length()); mPathData->mNumArguments = mNumArguments; mPathData->mNumCommands = mNumCommands; - - return NS_OK; } // --------------------------------------------------------------- diff --git a/content/svg/content/src/nsSVGPathDataParser.h b/content/svg/content/src/nsSVGPathDataParser.h index 140453cf2fb..06ee8ffce0d 100644 --- a/content/svg/content/src/nsSVGPathDataParser.h +++ b/content/svg/content/src/nsSVGPathDataParser.h @@ -72,7 +72,7 @@ protected: virtual nsresult StoreEllipticalArc(PRBool absCoords, float x, float y, float r1, float r2, float angle, PRBool largeArcFlag, PRBool sweepFlag) = 0; - nsresult Match(); + virtual nsresult Match(); nsresult MatchCoordPair(float* aX, float* aY); PRBool IsTokenCoordPairStarter(); @@ -144,7 +144,7 @@ class nsSVGPathDataParserToInternal : public nsSVGPathDataParser { public: nsSVGPathDataParserToInternal(nsSVGPathList *data) : mPathData(data) {} - virtual nsresult Parse(const nsAString &aValue); + nsresult Parse(const nsAString &aValue); protected: virtual nsresult StoreMoveTo(PRBool absCoords, float x, float y); @@ -187,7 +187,7 @@ private: nsresult PathLineTo(float x, float y); nsresult PathCurveTo(float x1, float y1, float x2, float y2, float x3, float y3); nsresult PathClose(); - nsresult PathFini(); + void PathFini(); }; class nsSVGPathDataParserToDOM : public nsSVGPathDataParser diff --git a/content/svg/content/src/nsSVGPathElement.cpp b/content/svg/content/src/nsSVGPathElement.cpp index 8612d74a942..6ba556a45a6 100644 --- a/content/svg/content/src/nsSVGPathElement.cpp +++ b/content/svg/content/src/nsSVGPathElement.cpp @@ -458,7 +458,10 @@ nsSVGPathElement::BeforeSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, if (aValue) { nsSVGPathDataParserToInternal parser(&mPathData); - parser.Parse(*aValue); + nsresult rv = parser.Parse(*aValue); + if (NS_FAILED(rv)) { + ReportAttributeParseFailure(GetOwnerDoc(), aName, *aValue); + } } else { mPathData.Clear(); } diff --git a/content/svg/content/src/nsSVGPathSegList.cpp b/content/svg/content/src/nsSVGPathSegList.cpp index 922323143b7..8fea0e2b946 100644 --- a/content/svg/content/src/nsSVGPathSegList.cpp +++ b/content/svg/content/src/nsSVGPathSegList.cpp @@ -132,12 +132,10 @@ NS_INTERFACE_MAP_END NS_IMETHODIMP nsSVGPathSegList::SetValueString(const nsAString& aValue) { - nsresult rv; - WillModify(); ReleaseSegments(PR_FALSE); nsSVGPathDataParserToDOM parser(&mSegments); - rv = parser.Parse(aValue); + nsresult rv = parser.Parse(aValue); PRInt32 count = mSegments.Count(); for (PRInt32 i=0; i xforms; nsSVGTransformListParser parser(&xforms); - rv = parser.Parse(aValue); + nsresult rv = parser.Parse(aValue); if (NS_FAILED(rv)) { // there was a parse error. diff --git a/content/svg/content/src/nsSVGTransformListParser.h b/content/svg/content/src/nsSVGTransformListParser.h index 7b62f8822d3..ce191304392 100644 --- a/content/svg/content/src/nsSVGTransformListParser.h +++ b/content/svg/content/src/nsSVGTransformListParser.h @@ -60,7 +60,7 @@ private: nsCOMArray *mTransform; // helpers - nsresult Match(); + virtual nsresult Match(); nsresult MatchNumberArguments(float *aResult, PRUint32 aMaxNum, diff --git a/layout/reftests/svg/path-02.svg b/layout/reftests/svg/path-02.svg new file mode 100644 index 00000000000..a00fa35c6fb --- /dev/null +++ b/layout/reftests/svg/path-02.svg @@ -0,0 +1,15 @@ + + + Testcase for path with errors + + + + + + + + + diff --git a/layout/reftests/svg/reftest.list b/layout/reftests/svg/reftest.list index 019864513b9..636d747baed 100644 --- a/layout/reftests/svg/reftest.list +++ b/layout/reftests/svg/reftest.list @@ -115,6 +115,7 @@ fails == inline-in-xul-basic-01.xul pass.svg == opacity-and-gradient-02.svg opacity-and-gradient-02-ref.svg == opacity-and-pattern-01.svg pass.svg == path-01.svg path-01-ref.svg +== path-02.svg pass.svg == pattern-live-01a.svg pattern-live-01-ref.svg == pattern-live-01b.svg pattern-live-01-ref.svg == pattern-live-01c.svg pattern-live-01-ref.svg