diff --git a/include/XSLT/impl/xslt_processing_instruction.hpp b/include/XSLT/impl/xslt_processing_instruction.hpp index 37a674ea..3965d1f7 100755 --- a/include/XSLT/impl/xslt_processing_instruction.hpp +++ b/include/XSLT/impl/xslt_processing_instruction.hpp @@ -1,6 +1,7 @@ #ifndef ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP #define ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP +#include #include "xslt_item.hpp" namespace Arabica @@ -21,17 +22,37 @@ public: virtual void execute(const DOM::Node& node, ExecutionContext& context) const { std::string name = name_->evaluateAsString(node, context.xpathContext()); - if(name.empty()) - throw SAX::SAXException("xsl:processing-instruction : name attribute must evaluate to a valid name"); + validate_name(name); context.sink().start_processing_instruction(name); - execute_children(node, context); - context.sink().end_processing_instruction(); } // execute private: + void validate_name(const std::string& name) const + { + if(name.empty()) + throw SAX::SAXException("xsl:processing-instruction : name attribute must evaluate to a valid name"); + + if(name.length() != 3) + return; + + typedef Arabica::text::Unicode UnicodeT; + + if((name[0] != UnicodeT::CAPITAL_X) && + (name[0] != UnicodeT::LOWERCASE_X)) + return; + if((name[1] != UnicodeT::CAPITAL_M) && + (name[1] != UnicodeT::LOWERCASE_M)) + return; + if((name[2] != UnicodeT::CAPITAL_L) && + (name[2] != UnicodeT::LOWERCASE_L)) + return; + + throw SAX::SAXException("xsl:processing-instruction name can not be 'xml'"); + } // validate_name + Arabica::XPath::XPathExpressionPtr name_; }; // class ProcessingInstruction diff --git a/tests/XSLT/testsuite/TESTS/arabica-catalog.xml b/tests/XSLT/testsuite/TESTS/arabica-catalog.xml index 7d11e304..849d24d6 100755 --- a/tests/XSLT/testsuite/TESTS/arabica-catalog.xml +++ b/tests/XSLT/testsuite/TESTS/arabica-catalog.xml @@ -19,6 +19,30 @@ error02.xsl + + errors + xsl:processing-instruction name cannot be 'xml' + + data.xml + error03.xsl + + + + errors + xsl:processing-instruction name cannot be 'xml' + + data.xml + error04.xsl + + + + errors + xsl:processing-instruction name cannot be 'xml' + + data.xml + error05.xsl + + include diff --git a/tests/XSLT/testsuite/TESTS/arabica/errors/error03.xsl b/tests/XSLT/testsuite/TESTS/arabica/errors/error03.xsl new file mode 100755 index 00000000..9a3897f7 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/errors/error03.xsl @@ -0,0 +1,11 @@ + + + + + + + woo + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/errors/error04.xsl b/tests/XSLT/testsuite/TESTS/arabica/errors/error04.xsl new file mode 100755 index 00000000..a55a5624 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/errors/error04.xsl @@ -0,0 +1,11 @@ + + + + + + + woo + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/errors/error05.xsl b/tests/XSLT/testsuite/TESTS/arabica/errors/error05.xsl new file mode 100755 index 00000000..cab03c62 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/errors/error05.xsl @@ -0,0 +1,11 @@ + + + + + + + woo + + +