From 487761485fea0ddd7e08263e01e40156798db57a Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 19 May 2017 11:42:36 +0200 Subject: Fixed issue 134 with remote scripts --- src/uscxml/interpreter/BasicContentExecutor.cpp | 2 +- src/uscxml/interpreter/InterpreterImpl.cpp | 23 +++++++++++++++++++++++ test/issues/test-issue134.js | 1 + test/issues/test-issue134.scxml | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/issues/test-issue134.js create mode 100644 test/issues/test-issue134.scxml diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 9796c4c..696b575 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -289,7 +289,7 @@ void BasicContentExecutor::processLog(XERCESC_NS::DOMElement* content) { } void BasicContentExecutor::processScript(XERCESC_NS::DOMElement* content) { - // download as necessary + // contents were already downloaded in setupDOM, see to SCXML rec 5.8 std::string scriptContent(X(content->getTextContent())); _callbacks->eval(scriptContent); diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 60448f9..f7a46fc 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -295,6 +295,29 @@ SCXML_STOP_SEARCH: _name = _baseURL.pathComponents().back(); } + // download all script, see issue 134 + std::list scripts = DOMUtils::filterChildElements(_xmlPrefix + "script", _scxml, true); + for (auto script : scripts) { + if (HAS_ATTR(script, kXMLCharSource)) { + std::string src = ATTR(script, kXMLCharSource); + std::string contents; + if (src.size() > 0) { + URL url(src); + if (!url.isAbsolute()) { + url = URL::resolve(url, _baseURL); + } + contents = url.getInContent(); + } else { + ERROR_COMMUNICATION2(exc, "Empty source attribute", script); + throw exc; + } + + XERCESC_NS::DOMText* scriptText = _document->createTextNode(X(contents)); + XERCESC_NS::DOMNode* newNode = _document->importNode(scriptText, true); + script->appendChild(newNode); + } + } + _binding = (HAS_ATTR(_scxml, kXMLCharBinding) && iequals(ATTR(_scxml, kXMLCharBinding), "late") ? LATE : EARLY); } diff --git a/test/issues/test-issue134.js b/test/issues/test-issue134.js new file mode 100644 index 0000000..6b3e64f --- /dev/null +++ b/test/issues/test-issue134.js @@ -0,0 +1 @@ +Var1 = 1; \ No newline at end of file diff --git a/test/issues/test-issue134.scxml b/test/issues/test-issue134.scxml new file mode 100644 index 0000000..973065d --- /dev/null +++ b/test/issues/test-issue134.scxml @@ -0,0 +1,14 @@ + + + + + + +