From 83894f9e17ce507f6ea963170c70d049577558ae Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 2 Dec 2008 17:43:46 +0000 Subject: [PATCH] Started reinstating loop checking during imports and includes. Loops in includes are detected, however imports are not yet. --- .../impl/handler/xslt_include_handler.hpp | 50 ++++++++++++++----- .../XSLT/testsuite/TESTS/arabica-catalog.xml | 21 ++++++++ .../TESTS/arabica/include/include03.xsl | 9 ++++ .../TESTS/arabica/include/include03a.xsl | 9 ++++ .../TESTS/arabica/include/include03b.xsl | 9 ++++ .../TESTS/arabica/include/include03c.xsl | 9 ++++ .../TESTS/arabica/include/include04.xsl | 9 ++++ .../TESTS/arabica/include/include04a.xsl | 8 +++ .../TESTS/arabica/include/include04b.xsl | 8 +++ .../TESTS/arabica/include/include04c.xsl | 8 +++ .../TESTS/arabica/include/include05.xsl | 9 ++++ .../TESTS/arabica/include/include05a.xsl | 8 +++ .../TESTS/arabica/include/include05b.xsl | 8 +++ .../TESTS/arabica/include/include05c.xsl | 9 ++++ 14 files changed, 162 insertions(+), 12 deletions(-) create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include03.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include03a.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include03b.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include03c.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include04.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include04a.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include04b.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include04c.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include05.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include05a.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include05b.xsl create mode 100644 tests/XSLT/testsuite/TESTS/arabica/include/include05c.xsl diff --git a/include/XSLT/impl/handler/xslt_include_handler.hpp b/include/XSLT/impl/handler/xslt_include_handler.hpp index 52cb1f8b..9b97d985 100644 --- a/include/XSLT/impl/handler/xslt_include_handler.hpp +++ b/include/XSLT/impl/handler/xslt_include_handler.hpp @@ -54,8 +54,7 @@ public: if(localName == "import") { std::string href = validate_href(qName, atts); - //check_for_loops(import_stack_, href); - import_stack_.push_back(std::make_pair(href, context_->next_precedence())); + import_stack_.push_back(href, context_->next_precedence()); return; } // if(localName == "import") if(localName == "include") @@ -111,10 +110,8 @@ public: { while(!import_stack_.empty()) { - ImportStack::iterator import = import_stack_.end()-1; - size_t index = import_stack_.size() - 1; - include_stylesheet(import_stack_.back().first, import_stack_.back().second); - import_stack_.erase(import_stack_.begin() + index); + include_stylesheet(import_stack_.current().first, import_stack_.current().second); + import_stack_.pop(); } // while ... } // unwind_imports @@ -128,20 +125,20 @@ private: return context_->makeAbsolute(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 "; - for(std::vector::const_iterator i = stack.begin(), ie = stack.end(); i != ie; ++i) + for(std::vector::const_iterator i = current_includes_.begin(), ie = current_includes_.end(); i != ie; ++i) error += "\n " + *i; throw std::runtime_error(error); } // if ... } // check_for_loops -*/ + 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); std::string prev = context_->setBase(href); @@ -168,7 +165,36 @@ private: CompilationContext* context_; bool no_content_; - typedef std::vector > ImportStack; + class ImportStack + { + public: + typedef std::pair ImportHref; + + ImportStack() { } + + void push_back(const std::string href, const Precedence& precedence) + { + stack_.push_back(std::make_pair(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 stack_; + mutable size_t most_recent_; + }; // class ImportStack + ImportStack import_stack_; std::vector current_includes_; diff --git a/tests/XSLT/testsuite/TESTS/arabica-catalog.xml b/tests/XSLT/testsuite/TESTS/arabica-catalog.xml index 23ca8ef2..c07b7818 100755 --- a/tests/XSLT/testsuite/TESTS/arabica-catalog.xml +++ b/tests/XSLT/testsuite/TESTS/arabica-catalog.xml @@ -91,6 +91,27 @@ include02.out + + include + + data.xml + include03.xsl + + + + include + + data.xml + include04.xsl + + + + include + + data.xml + include05.xsl + + processing-instruction diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include03.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include03.xsl new file mode 100644 index 00000000..c02c8498 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include03.xsl @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include03a.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include03a.xsl new file mode 100644 index 00000000..87d30857 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include03a.xsl @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include03b.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include03b.xsl new file mode 100644 index 00000000..2729d5e7 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include03b.xsl @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include03c.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include03c.xsl new file mode 100644 index 00000000..c02c8498 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include03c.xsl @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include04.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include04.xsl new file mode 100644 index 00000000..674a43ec --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include04.xsl @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include04a.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include04a.xsl new file mode 100644 index 00000000..ff369d3a --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include04a.xsl @@ -0,0 +1,8 @@ + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include04b.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include04b.xsl new file mode 100644 index 00000000..dbd71188 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include04b.xsl @@ -0,0 +1,8 @@ + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include04c.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include04c.xsl new file mode 100644 index 00000000..46f29927 --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include04c.xsl @@ -0,0 +1,8 @@ + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include05.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include05.xsl new file mode 100644 index 00000000..caa4137e --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include05.xsl @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include05a.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include05a.xsl new file mode 100644 index 00000000..c966919a --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include05a.xsl @@ -0,0 +1,8 @@ + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include05b.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include05b.xsl new file mode 100644 index 00000000..ffe3313c --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include05b.xsl @@ -0,0 +1,8 @@ + + + + + + + diff --git a/tests/XSLT/testsuite/TESTS/arabica/include/include05c.xsl b/tests/XSLT/testsuite/TESTS/arabica/include/include05c.xsl new file mode 100644 index 00000000..caa4137e --- /dev/null +++ b/tests/XSLT/testsuite/TESTS/arabica/include/include05c.xsl @@ -0,0 +1,9 @@ + + + + + + + +