mirror of
https://github.com/jezhiggins/arabica
synced 2024-11-17 07:48:50 +01:00
xsl:processing-instruction shouldn't allow xml as the name
This commit is contained in:
parent
cdebc3d128
commit
c7c0c3d36c
5 changed files with 82 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
#ifndef ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP
|
||||
#define ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP
|
||||
|
||||
#include <text/UnicodeCharacters.hpp>
|
||||
#include "xslt_item.hpp"
|
||||
|
||||
namespace Arabica
|
||||
|
@ -21,17 +22,37 @@ public:
|
|||
virtual void execute(const DOM::Node<std::string>& 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<char> 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<std::string> name_;
|
||||
}; // class ProcessingInstruction
|
||||
|
||||
|
|
|
@ -19,6 +19,30 @@
|
|||
<input-file role="principal-stylesheet">error02.xsl</input-file>
|
||||
</scenario>
|
||||
</test-case>
|
||||
<test-case id="error03">
|
||||
<file-path>errors</file-path>
|
||||
<purpose>xsl:processing-instruction name cannot be 'xml'</purpose>
|
||||
<scenario operation="execution-error">
|
||||
<input-file role="principal-data">data.xml</input-file>
|
||||
<input-file role="principal-stylesheet">error03.xsl</input-file>
|
||||
</scenario>
|
||||
</test-case>
|
||||
<test-case id="error04">
|
||||
<file-path>errors</file-path>
|
||||
<purpose>xsl:processing-instruction name cannot be 'xml'</purpose>
|
||||
<scenario operation="execution-error">
|
||||
<input-file role="principal-data">data.xml</input-file>
|
||||
<input-file role="principal-stylesheet">error04.xsl</input-file>
|
||||
</scenario>
|
||||
</test-case>
|
||||
<test-case id="error05">
|
||||
<file-path>errors</file-path>
|
||||
<purpose>xsl:processing-instruction name cannot be 'xml'</purpose>
|
||||
<scenario operation="execution-error">
|
||||
<input-file role="principal-data">data.xml</input-file>
|
||||
<input-file role="principal-stylesheet">error05.xsl</input-file>
|
||||
</scenario>
|
||||
</test-case>
|
||||
<test-case id="include01">
|
||||
<file-path>include</file-path>
|
||||
<scenario operation="standard">
|
||||
|
|
11
tests/XSLT/testsuite/TESTS/arabica/errors/error03.xsl
Executable file
11
tests/XSLT/testsuite/TESTS/arabica/errors/error03.xsl
Executable file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
version="1.0">
|
||||
|
||||
<xsl:output method="xml"/>
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:processing-instruction name="xml">woo</xsl:processing-instruction>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
11
tests/XSLT/testsuite/TESTS/arabica/errors/error04.xsl
Executable file
11
tests/XSLT/testsuite/TESTS/arabica/errors/error04.xsl
Executable file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
version="1.0">
|
||||
|
||||
<xsl:output method="xml"/>
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:processing-instruction name="XML">woo</xsl:processing-instruction>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
11
tests/XSLT/testsuite/TESTS/arabica/errors/error05.xsl
Executable file
11
tests/XSLT/testsuite/TESTS/arabica/errors/error05.xsl
Executable file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
version="1.0">
|
||||
|
||||
<xsl:output method="xml"/>
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:processing-instruction name="xMl">woo</xsl:processing-instruction>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
Loading…
Reference in a new issue