mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-30 08:38:15 +01:00
Started reinstating loop checking during imports and includes. Loops in
includes are detected, however imports are not yet.
This commit is contained in:
parent
3ea6fde701
commit
83894f9e17
14 changed files with 162 additions and 12 deletions
|
@ -54,8 +54,7 @@ public:
|
||||||
if(localName == "import")
|
if(localName == "import")
|
||||||
{
|
{
|
||||||
std::string href = validate_href(qName, atts);
|
std::string href = validate_href(qName, atts);
|
||||||
//check_for_loops(import_stack_, href);
|
import_stack_.push_back(href, context_->next_precedence());
|
||||||
import_stack_.push_back(std::make_pair(href, context_->next_precedence()));
|
|
||||||
return;
|
return;
|
||||||
} // if(localName == "import")
|
} // if(localName == "import")
|
||||||
if(localName == "include")
|
if(localName == "include")
|
||||||
|
@ -111,10 +110,8 @@ public:
|
||||||
{
|
{
|
||||||
while(!import_stack_.empty())
|
while(!import_stack_.empty())
|
||||||
{
|
{
|
||||||
ImportStack::iterator import = import_stack_.end()-1;
|
include_stylesheet(import_stack_.current().first, import_stack_.current().second);
|
||||||
size_t index = import_stack_.size() - 1;
|
import_stack_.pop();
|
||||||
include_stylesheet(import_stack_.back().first, import_stack_.back().second);
|
|
||||||
import_stack_.erase(import_stack_.begin() + index);
|
|
||||||
} // while ...
|
} // while ...
|
||||||
} // unwind_imports
|
} // unwind_imports
|
||||||
|
|
||||||
|
@ -128,20 +125,20 @@ private:
|
||||||
return context_->makeAbsolute(href);
|
return context_->makeAbsolute(href);
|
||||||
} // validate_href
|
} // validate_href
|
||||||
|
|
||||||
/* void check_for_loops(const ImportStack& stack, const std::string& href)
|
void check_for_loops(const std::string& href)
|
||||||
{
|
{
|
||||||
if(std::find(stack.begin(), stack.end(), candidate) != stack.end())
|
if(std::find(current_includes_.begin(), current_includes_.end(), href) != current_includes_.end())
|
||||||
{
|
{
|
||||||
std::string error = "Stylesheet '" + href + "' includes/imports itself ";
|
std::string error = "Stylesheet '" + href + "' includes/imports itself ";
|
||||||
for(std::vector<std::string>::const_iterator i = stack.begin(), ie = stack.end(); i != ie; ++i)
|
for(std::vector<std::string>::const_iterator i = current_includes_.begin(), ie = current_includes_.end(); i != ie; ++i)
|
||||||
error += "\n " + *i;
|
error += "\n " + *i;
|
||||||
throw std::runtime_error(error);
|
throw std::runtime_error(error);
|
||||||
} // if ...
|
} // if ...
|
||||||
} // check_for_loops
|
} // check_for_loops
|
||||||
*/
|
|
||||||
void include_stylesheet(const std::string& href, const Precedence& precedence)
|
void include_stylesheet(const std::string& href, const Precedence& precedence)
|
||||||
{
|
{
|
||||||
//check_for_loops(current_includes_, href);
|
check_for_loops(href);
|
||||||
current_includes_.push_back(href);
|
current_includes_.push_back(href);
|
||||||
|
|
||||||
std::string prev = context_->setBase(href);
|
std::string prev = context_->setBase(href);
|
||||||
|
@ -168,7 +165,36 @@ private:
|
||||||
CompilationContext* context_;
|
CompilationContext* context_;
|
||||||
bool no_content_;
|
bool no_content_;
|
||||||
|
|
||||||
typedef std::vector<std::pair<std::string, Precedence> > ImportStack;
|
class ImportStack
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::pair<std::string, Precedence> ImportHref;
|
||||||
|
|
||||||
|
ImportStack() { }
|
||||||
|
|
||||||
|
void push_back(const std::string href, const Precedence& precedence)
|
||||||
|
{
|
||||||
|
stack_.push_back(std::make_pair<std::string, Precedence>(href, precedence));
|
||||||
|
} // push_back
|
||||||
|
|
||||||
|
bool empty() const { return stack_.empty(); }
|
||||||
|
|
||||||
|
const ImportHref& current() const
|
||||||
|
{
|
||||||
|
most_recent_ = stack_.size() - 1;
|
||||||
|
return stack_[most_recent_];
|
||||||
|
} // current
|
||||||
|
|
||||||
|
void pop()
|
||||||
|
{
|
||||||
|
stack_.erase(stack_.begin() + most_recent_);
|
||||||
|
} // pop
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<ImportHref> stack_;
|
||||||
|
mutable size_t most_recent_;
|
||||||
|
}; // class ImportStack
|
||||||
|
|
||||||
ImportStack import_stack_;
|
ImportStack import_stack_;
|
||||||
std::vector<std::string> current_includes_;
|
std::vector<std::string> current_includes_;
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,27 @@
|
||||||
<output-file role="principal" compare="XML">include02.out</output-file>
|
<output-file role="principal" compare="XML">include02.out</output-file>
|
||||||
</scenario>
|
</scenario>
|
||||||
</test-case>
|
</test-case>
|
||||||
|
<test-case id="include03">
|
||||||
|
<file-path>include</file-path>
|
||||||
|
<scenario operation="execution-error">
|
||||||
|
<input-file role="principal-data">data.xml</input-file>
|
||||||
|
<input-file role="principal-stylesheet">include03.xsl</input-file>
|
||||||
|
</scenario>
|
||||||
|
</test-case>
|
||||||
|
<test-case id="include04">
|
||||||
|
<file-path>include</file-path>
|
||||||
|
<scenario operation="execution-error">
|
||||||
|
<input-file role="principal-data">data.xml</input-file>
|
||||||
|
<input-file role="principal-stylesheet">include04.xsl</input-file>
|
||||||
|
</scenario>
|
||||||
|
</test-case>
|
||||||
|
<test-case id="include05">
|
||||||
|
<file-path>include</file-path>
|
||||||
|
<scenario operation="execution-error">
|
||||||
|
<input-file role="principal-data">data.xml</input-file>
|
||||||
|
<input-file role="principal-stylesheet">include05.xsl</input-file>
|
||||||
|
</scenario>
|
||||||
|
</test-case>
|
||||||
<test-case id="pi01">
|
<test-case id="pi01">
|
||||||
<file-path>processing-instruction</file-path>
|
<file-path>processing-instruction</file-path>
|
||||||
<scenario operation="standard">
|
<scenario operation="standard">
|
||||||
|
|
9
tests/XSLT/testsuite/TESTS/arabica/include/include03.xsl
Normal file
9
tests/XSLT/testsuite/TESTS/arabica/include/include03.xsl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?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:include href="include03a.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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:include href="include03b.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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:include href="include03c.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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:include href="include03a.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
9
tests/XSLT/testsuite/TESTS/arabica/include/include04.xsl
Normal file
9
tests/XSLT/testsuite/TESTS/arabica/include/include04.xsl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
version="1.0">
|
||||||
|
|
||||||
|
<xsl:import href="include04a.xsl"/>
|
||||||
|
|
||||||
|
<xsl:output method="xml"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
version="1.0">
|
||||||
|
|
||||||
|
|
||||||
|
<xsl:import href="include04b.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
version="1.0">
|
||||||
|
|
||||||
|
|
||||||
|
<xsl:import href="include04c.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
version="1.0">
|
||||||
|
|
||||||
|
|
||||||
|
<xsl:import href="include04a.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
9
tests/XSLT/testsuite/TESTS/arabica/include/include05.xsl
Normal file
9
tests/XSLT/testsuite/TESTS/arabica/include/include05.xsl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?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:include href="include05a.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
version="1.0">
|
||||||
|
|
||||||
|
|
||||||
|
<xsl:import href="include05b.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
version="1.0">
|
||||||
|
|
||||||
|
|
||||||
|
<xsl:import href="include05c.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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:include href="include05a.xsl"/>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
Loading…
Add table
Reference in a new issue