Check attribute names in setAttribute

This commit is contained in:
jez 2010-12-24 22:44:43 +00:00
parent 4d20439527
commit 56a3f9397f
3 changed files with 25 additions and 25 deletions

View file

@ -15,7 +15,6 @@
#include <DOM/Simple/NotationImpl.hpp> #include <DOM/Simple/NotationImpl.hpp>
#include <DOM/Simple/ElementByTagImpl.hpp> #include <DOM/Simple/ElementByTagImpl.hpp>
#include <DOM/Simple/NodeImpl.hpp> #include <DOM/Simple/NodeImpl.hpp>
#include <XML/XMLCharacterClasses.hpp>
#include <set> #include <set>
#include <list> #include <list>
@ -527,28 +526,6 @@ class DocumentImpl : public DOM::Document_impl<stringT, string_adaptorT>,
throw DOM::DOMException(DOM::DOMException::HIERARCHY_REQUEST_ERR); throw DOM::DOMException(DOM::DOMException::HIERARCHY_REQUEST_ERR);
} // checkChildType } // checkChildType
void checkName(const stringT& str) const
{
if(string_adaptorT::length(str) == 0)
throw DOM::DOMException(DOM::DOMException::INVALID_CHARACTER_ERR);
typedef typename string_adaptorT::const_iterator const_iterator;
const_iterator i = string_adaptorT::begin(str);
const_iterator ie = string_adaptorT::end(str);
for( ; i != ie; ++i)
if(!XML::is_name_char(*i))
throw DOM::DOMException(DOM::DOMException::INVALID_CHARACTER_ERR);
} // checkName
void checkChars(const stringT& str) const
{
typedef typename string_adaptorT::const_iterator const_iterator;
const_iterator i = string_adaptorT::begin(str);
const_iterator ie = string_adaptorT::end(str);
for( ; i != ie; ++i)
if(!XML::is_char(*i))
throw DOM::DOMException(DOM::DOMException::INVALID_CHARACTER_ERR);
} // checkChars
private: private:
DOMElement_implT* documentElement_; DOMElement_implT* documentElement_;
DOMDocumentType_implT* documentType_; DOMDocumentType_implT* documentType_;

View file

@ -51,6 +51,7 @@ class ElementImpl : public DOM::Element_impl<stringT, string_adaptorT>,
virtual void setAttribute(const stringT& name, const stringT& value) virtual void setAttribute(const stringT& name, const stringT& value)
{ {
checkName(name);
attributes_.setAttribute(name, value); attributes_.setAttribute(name, value);
} // setAttribute } // setAttribute
@ -88,6 +89,7 @@ class ElementImpl : public DOM::Element_impl<stringT, string_adaptorT>,
virtual void setAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName, const stringT& value) virtual void setAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName, const stringT& value)
{ {
checkName(qualifiedName);
attributes_.setAttributeNS(namespaceURI, qualifiedName, value); attributes_.setAttributeNS(namespaceURI, qualifiedName, value);
} // setAttributeNS } // setAttributeNS

View file

@ -3,12 +3,11 @@
//////////////////////////// ////////////////////////////
// C++ DOM definition // C++ DOM definition
//
// $Id$
//////////////////////////// ////////////////////////////
#include <DOM/Node.hpp> #include <DOM/Node.hpp>
#include <DOM/DOMException.hpp> #include <DOM/DOMException.hpp>
#include <XML/XMLCharacterClasses.hpp>
#include <deque> #include <deque>
#include <algorithm> #include <algorithm>
@ -205,6 +204,28 @@ class NodeImpl : virtual public DOM::Node_impl<stringT, string_adaptorT>
} // throwIfReadOnly } // throwIfReadOnly
protected: protected:
void checkName(const stringT& str) const
{
if(string_adaptorT::length(str) == 0)
throw DOM::DOMException(DOM::DOMException::INVALID_CHARACTER_ERR);
typedef typename string_adaptorT::const_iterator const_iterator;
const_iterator i = string_adaptorT::begin(str);
const_iterator ie = string_adaptorT::end(str);
for( ; i != ie; ++i)
if(!XML::is_name_char(*i))
throw DOM::DOMException(DOM::DOMException::INVALID_CHARACTER_ERR);
} // checkName
void checkChars(const stringT& str) const
{
typedef typename string_adaptorT::const_iterator const_iterator;
const_iterator i = string_adaptorT::begin(str);
const_iterator ie = string_adaptorT::end(str);
for( ; i != ie; ++i)
if(!XML::is_char(*i))
throw DOM::DOMException(DOM::DOMException::INVALID_CHARACTER_ERR);
} // checkChars
NodeImplT* parentNode_; NodeImplT* parentNode_;
DocumentImplT* ownerDoc_; DocumentImplT* ownerDoc_;
NodeImplT* prevSibling_; NodeImplT* prevSibling_;