Author: amassari
Date: Thu Aug 20 16:19:44 2009
New Revision: 806238
URL: http://svn.apache.org/viewvc?rev=806238&view=rev
Log:
Improved validation of xsi:nil
Modified:
xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp
xerces/c/trunk/src/xercesc/internal/IGXMLScanner2.cpp
xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp
xerces/c/trunk/src/xercesc/internal/XSAXMLScanner.cpp
xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.cpp
xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.hpp
Modified: xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp?rev=806238&r1=806237&r2=806238&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp Thu Aug 20 16:19:44
2009
@@ -2729,7 +2729,7 @@
}
}
else if (fGrammarType == Grammar::SchemaGrammarType) {
- ((SchemaValidator*)fValidator)->setNillable(false);
+ ((SchemaValidator*)fValidator)->resetNillable();
}
if (fGrammarType == Grammar::SchemaGrammarType)
Modified: xerces/c/trunk/src/xercesc/internal/IGXMLScanner2.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/internal/IGXMLScanner2.cpp?rev=806238&r1=806237&r2=806238&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/IGXMLScanner2.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/IGXMLScanner2.cpp Thu Aug 20 16:19:44
2009
@@ -1734,6 +1734,10 @@
((SchemaValidator*)
fValidator)->normalizeWhiteSpace(tempDV, valuePtr, fXsiNil, true);
if(XMLString::equals(fXsiNil.getRawBuffer(),
SchemaSymbols::fgATTVAL_TRUE))
((SchemaValidator*)fValidator)->setNillable(true);
+ else if(XMLString::equals(fXsiNil.getRawBuffer(),
SchemaSymbols::fgATTVAL_FALSE))
+ ((SchemaValidator*)fValidator)->setNillable(false);
+ else
+ emitError(XMLErrs::InvalidAttValue,
fXsiNil.getRawBuffer(), valuePtr);
fBufMgr.releaseBuffer(fXsiNil);
}
}
Modified: xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp?rev=806238&r1=806237&r2=806238&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp Thu Aug 20 16:19:44
2009
@@ -1724,7 +1724,7 @@
}
else if (fGrammarType == Grammar::SchemaGrammarType) {
- ((SchemaValidator*)fValidator)->setNillable(false);
+ ((SchemaValidator*)fValidator)->resetNillable();
}
if (fPSVIHandler)
@@ -3627,6 +3627,10 @@
((SchemaValidator*)
fValidator)->normalizeWhiteSpace(tempDV, valuePtr, fXsiNil, true);
if(XMLString::equals(fXsiNil.getRawBuffer(),
SchemaSymbols::fgATTVAL_TRUE))
((SchemaValidator*)fValidator)->setNillable(true);
+ else if(XMLString::equals(fXsiNil.getRawBuffer(),
SchemaSymbols::fgATTVAL_FALSE))
+ ((SchemaValidator*)fValidator)->setNillable(false);
+ else
+ emitError(XMLErrs::InvalidAttValue,
fXsiNil.getRawBuffer(), valuePtr);
fBufMgr.releaseBuffer(fXsiNil);
}
}
Modified: xerces/c/trunk/src/xercesc/internal/XSAXMLScanner.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/internal/XSAXMLScanner.cpp?rev=806238&r1=806237&r2=806238&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XSAXMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XSAXMLScanner.cpp Thu Aug 20 16:19:44
2009
@@ -677,6 +677,10 @@
((SchemaValidator*)
fValidator)->normalizeWhiteSpace(tempDV, valuePtr, fXsiNil, true);
if(XMLString::equals(fXsiNil.getRawBuffer(),
SchemaSymbols::fgATTVAL_TRUE))
((SchemaValidator*)fValidator)->setNillable(true);
+ else if(XMLString::equals(fXsiNil.getRawBuffer(),
SchemaSymbols::fgATTVAL_FALSE))
+ ((SchemaValidator*)fValidator)->setNillable(false);
+ else
+ emitError(XMLErrs::InvalidAttValue,
fXsiNil.getRawBuffer(), valuePtr);
fBufMgr.releaseBuffer(fXsiNil);
}
}
Modified: xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.cpp?rev=806238&r1=806237&r2=806238&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.cpp (original)
+++ xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.cpp Thu Aug 20
16:19:44 2009
@@ -52,6 +52,7 @@
, fGrammarResolver(0)
, fXsiType(0)
, fNil(false)
+ , fNilFound(false)
, fCurrentDatatypeValidator(0)
, fNotationBuf(0)
, fDatatypeBuffer(1023, manager)
@@ -171,114 +172,104 @@
XMLCh* value = fDatatypeBuffer.getRawBuffer();
XMLCh* elemDefaultValue = ((SchemaElementDecl*)
elemDecl)->getDefaultValue();
- if (fCurrentDatatypeValidator)
+ if (fNil)
{
- if (fNil)
+ if ((!XMLString::equals(value, XMLUni::fgZeroLenString))
+ || elemDefaultValue)
{
- if ((!XMLString::equals(value, XMLUni::fgZeroLenString))
- || elemDefaultValue)
- {
- emitError(XMLValid::NilAttrNotEmpty,
elemDecl->getFullName());
- fErrorOccurred = true;
+ emitError(XMLValid::NilAttrNotEmpty,
elemDecl->getFullName());
+ fErrorOccurred = true;
+ }
+ }
+ else if (fCurrentDatatypeValidator)
+ {
+ DatatypeValidator::ValidatorType eleDefDVType =
fCurrentDatatypeValidator->getType();
+ bool validateCanonical = false;
+ if (eleDefDVType == DatatypeValidator::NOTATION)
+ {
+ // if notation, need to bind URI to notation first
+ if (!fNotationBuf)
+ fNotationBuf = new (fMemoryManager) XMLBuffer(1023,
fMemoryManager);
+
+ // Make sure that this value maps to one of the
+ // notation values in the enumList parameter. We don't
have to
+ // look it up in the notation pool (if a notation)
because we
+ // will look up the enumerated values themselves. If they
are in
+ // the notation pool (after the Grammar is parsed), then
obviously
+ // this value will be legal since it matches one of them.
+ int colonPos = -1;
+ unsigned int uriId = getScanner()->resolveQName(value,
*fNotationBuf, ElemStack::Mode_Element, colonPos);
+
+ const XMLCh* uriText = getScanner()->getURIText(uriId);
+ if (uriText && *uriText) {
+ fNotationBuf->set(uriText);
+ fNotationBuf->append(chColon);
+ fNotationBuf->append(&value[colonPos + 1]);
+ value = fNotationBuf->getRawBuffer();
}
}
- else
+
+ if (elemDefaultValue)
{
- DatatypeValidator::ValidatorType eleDefDVType =
fCurrentDatatypeValidator->getType();
- bool validateCanonical = false;
- if (eleDefDVType == DatatypeValidator::NOTATION)
+ if (XMLString::equals(value, XMLUni::fgZeroLenString))
{
- // if notation, need to bind URI to notation first
- if (!fNotationBuf)
- fNotationBuf = new (fMemoryManager)
XMLBuffer(1023, fMemoryManager);
-
- // Make sure that this value maps to one of the
- // notation values in the enumList parameter. We
don't have to
- // look it up in the notation pool (if a notation)
because we
- // will look up the enumerated values themselves. If
they are in
- // the notation pool (after the Grammar is parsed),
then obviously
- // this value will be legal since it matches one of
them.
- int colonPos = -1;
- unsigned int uriId = getScanner()->resolveQName(value,
*fNotationBuf, ElemStack::Mode_Element, colonPos);
-
- const XMLCh* uriText = getScanner()->getURIText(uriId);
- if (uriText && *uriText) {
- fNotationBuf->set(uriText);
- fNotationBuf->append(chColon);
- fNotationBuf->append(&value[colonPos + 1]);
- value = fNotationBuf->getRawBuffer();
+ fElemIsSpecified = true;
+ // if this element didn't specified any value
+ // use default value
+ if (getScanner()->getDocHandler())
+
getScanner()->getDocHandler()->docCharacters(elemDefaultValue,
XMLString::stringLen(elemDefaultValue), false);
+
+ // Normally for default value, it has been validated
already during TraverseSchema
+ // But if there was a xsi:type and this validator is
fXsiTypeValidator,
+ // need to validate again
+ // we determine this if the current content dataype
validator
+ // is neither the one in the element nor the one in
the current
+ // complex type (if any)
+ if ((fCurrentDatatypeValidator !=
((SchemaElementDecl*)elemDecl)->getDatatypeValidator())
+ && (!fTypeStack->peek() ||
(fCurrentDatatypeValidator != fTypeStack->peek()->getDatatypeValidator()))) {
+ value = elemDefaultValue;
+ validateCanonical = true;
}
+ else
+ value = 0;
}
-
- if (elemDefaultValue)
+ else
{
- if (XMLString::equals(value, XMLUni::fgZeroLenString))
+ // this element has specified some value
+ // if the flag is FIXED, then this value must be same
as default value
+ if ((((SchemaElementDecl*)elemDecl)->getMiscFlags() &
SchemaSymbols::XSD_FIXED) != 0)
{
- fElemIsSpecified = true;
- // if this element didn't specified any value
- // use default value
- if (getScanner()->getDocHandler())
-
getScanner()->getDocHandler()->docCharacters(elemDefaultValue,
XMLString::stringLen(elemDefaultValue), false);
-
- // Normally for default value, it has been
validated already during TraverseSchema
- // But if there was a xsi:type and this validator
is fXsiTypeValidator,
- // need to validate again
- // we determine this if the current content
dataype validator
- // is neither the one in the element nor the one
in the current
- // complex type (if any)
- if ((fCurrentDatatypeValidator !=
((SchemaElementDecl*)elemDecl)->getDatatypeValidator())
- && (!fTypeStack->peek() ||
(fCurrentDatatypeValidator != fTypeStack->peek()->getDatatypeValidator()))) {
- value = elemDefaultValue;
- validateCanonical = true;
- }
- else
- value = 0;
- }
- else
- {
- // this element has specified some value
- // if the flag is FIXED, then this value must be
same as default value
- if
((((SchemaElementDecl*)elemDecl)->getMiscFlags() & SchemaSymbols::XSD_FIXED) !=
0)
+ if (fCurrentDatatypeValidator->compare(value,
elemDefaultValue, fMemoryManager) != 0 )
{
- if (fCurrentDatatypeValidator->compare(value,
elemDefaultValue, fMemoryManager) != 0 )
- {
-
emitError(XMLValid::FixedDifferentFromActual, elemDecl->getFullName());
- fErrorOccurred = true;
- }
+ emitError(XMLValid::FixedDifferentFromActual,
elemDecl->getFullName());
+ fErrorOccurred = true;
}
}
}
- else
+ }
+
+ if ((!fErrorOccurred) && value)
+ {
+ try {
+ fCurrentDatatypeValidator->validate(value,
getScanner()->getValidationContext(), fMemoryManager);
+ if (validateCanonical) {
+ XMLCh* canonical = (XMLCh*)
fCurrentDatatypeValidator->getCanonicalRepresentation(value, fMemoryManager);
+ ArrayJanitor<XMLCh> tempCanonical(canonical,
fMemoryManager);
+ fCurrentDatatypeValidator->validate(canonical,
getScanner()->getValidationContext(), fMemoryManager);
+ }
+ }
+ catch (XMLException& idve)
{
- // no default value, then check nillable
- if (XMLString::equals(value, XMLUni::fgZeroLenString)
- && (((SchemaElementDecl*)elemDecl)->getMiscFlags()
& SchemaSymbols::XSD_NILLABLE) != 0)
- value = 0;
+ emitError (XMLValid::DatatypeError, idve.getCode(),
idve.getMessage());
+ fErrorOccurred = true;
}
-
- if ((!fErrorOccurred) && value)
+ catch(const OutOfMemoryException&) {
+ throw;
+ }
+ catch (...)
{
- try {
- fCurrentDatatypeValidator->validate(value,
getScanner()->getValidationContext(), fMemoryManager);
- if (validateCanonical) {
- XMLCh* canonical = (XMLCh*)
fCurrentDatatypeValidator->getCanonicalRepresentation(value, fMemoryManager);
- ArrayJanitor<XMLCh> tempCanonical(canonical,
fMemoryManager);
- fCurrentDatatypeValidator->validate(canonical,
getScanner()->getValidationContext(), fMemoryManager);
- }
- }
- catch (XMLException& idve)
- {
- emitError (XMLValid::DatatypeError,
idve.getCode(), idve.getMessage());
- fErrorOccurred = true;
- }
- catch(const OutOfMemoryException&) {
- throw;
- }
- catch (...)
- {
- emitError(XMLValid::GenericError);
- throw;
- }
+ emitError(XMLValid::GenericError);
+ throw;
}
}
}
@@ -310,6 +301,7 @@
// must rely on scanner to clear fDatatypeBuffer
// since it may need to query its contents after this method completes
fNil = false;
+ fNilFound = false;
fTrailing=false;
fSeenNonWhiteSpace = false;
fCurrentDatatypeValidator = 0;
@@ -348,6 +340,7 @@
fXsiType = 0;
fCurrentDatatypeValidator = 0;
fNil = false;
+ fNilFound = false;
fDatatypeBuffer.reset();
fErrorOccurred = false;
}
@@ -728,8 +721,9 @@
//
// Check whether this element allows Nillable
//
- if (fNil && (miscFlags & SchemaSymbols::XSD_NILLABLE) == 0 ) {
+ if (fNilFound && (miscFlags & SchemaSymbols::XSD_NILLABLE) == 0 ) {
fNil = false;
+ fNilFound = false;
emitError(XMLValid::NillNotAllowed, elemDef->getFullName());
fErrorOccurred = true;
}
Modified: xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.hpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.hpp?rev=806238&r1=806237&r2=806238&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.hpp (original)
+++ xerces/c/trunk/src/xercesc/validators/schema/SchemaValidator.hpp Thu Aug 20
16:19:44 2009
@@ -121,6 +121,7 @@
, const unsigned int uriId);
void setNillable(bool isNil);
+ void resetNillable();
void setErrorReporter(XMLErrorReporter* const errorReporter);
void setExitOnFirstFatal(const bool newValue);
void setDatatypeBuffer(const XMLCh* const value);
@@ -256,6 +257,8 @@
// Store the Schema Type Attribute Value if schema type is specified
//
// fNil
+ // Indicates if a nil value is acceptable
+ // fNilFound
// Indicates if Nillable has been set
// -----------------------------------------------------------------------
// The following used internally in the validator
@@ -293,6 +296,7 @@
GrammarResolver* fGrammarResolver;
QName* fXsiType;
bool fNil;
+ bool fNilFound;
DatatypeValidator* fCurrentDatatypeValidator;
XMLBuffer* fNotationBuf;
XMLBuffer fDatatypeBuffer;
@@ -324,6 +328,12 @@
inline void SchemaValidator::setNillable(bool isNil) {
fNil = isNil;
+ fNilFound = true;
+}
+
+inline void SchemaValidator::resetNillable() {
+ fNil = false;
+ fNilFound = false;
}
inline void SchemaValidator::setExitOnFirstFatal(const bool newValue) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]