[xmltooling] 37/65: SSPCPP-691 replace ignoreCase with caseSensitive

Ferenc Wágner wferi-guest at moszumanska.debian.org
Thu Jun 30 13:07:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

wferi-guest pushed a commit to branch debian/master
in repository xmltooling.

commit 9bfb85bc1b40844590541f2c3624d2dea1a81a92
Author: Rod Widdowson <rdw at steadingsoftware.com>
Date:   Wed Jun 8 16:48:42 2016 +0100

    SSPCPP-691 replace ignoreCase with caseSensitive
    
    https://issues.shibboleth.net/jira/browse/SSPCPP-691
    
    This commit creates a new helper function to do the right thing
    with respect to the (soon to be deprecated) "ignoreCase" Attribute
    and the (soon to be widespread) "caseSensitive" Attribute.
    
    In the rare cases of deprecated or broken function being encountered
    we grow a logging::Category and use it to log.
---
 xmltooling/util/XMLHelper.cpp      | 37 +++++++++++++++++++++++++++++++++++++
 xmltooling/util/XMLHelper.h        | 14 ++++++++++++++
 xmltoolingtest/data/IgnoreCase.xml |  9 +++++++++
 xmltoolingtest/xmltoolingtest.h    | 37 +++++++++++++++++++++++++++++++++++--
 4 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/xmltooling/util/XMLHelper.cpp b/xmltooling/util/XMLHelper.cpp
index 2682395..79c3fb9 100644
--- a/xmltooling/util/XMLHelper.cpp
+++ b/xmltooling/util/XMLHelper.cpp
@@ -25,6 +25,7 @@
  */
 
 #include "internal.h"
+#include "logging.h"
 #include "exceptions.h"
 #include "QName.h"
 #include "XMLObject.h"
@@ -362,6 +363,42 @@ bool XMLHelper::getAttrBool(const DOMElement* e, bool defValue, const XMLCh* loc
     return defValue;
 }
 
+bool XMLHelper::getCaseSensitive(const xercesc::DOMElement* e, bool defValue, const XMLCh* ns)
+{
+    static const XMLCh ignoreCase[] =   UNICODE_LITERAL_10(i,g,n,o,r,e,C,a,s,e);
+    static const XMLCh caseSensitive[] =   UNICODE_LITERAL_13(c,a,s,e,S,e,n,s,i,t,i,v,e);
+    static bool ignoreCaseWarned = false;
+    bool result=defValue;
+
+    if (e) {
+        const XMLCh* ic = e->getAttributeNS(ns, ignoreCase);
+        if (ic && * ic) {
+            if (!ignoreCaseWarned) {
+                logging::Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").warn("Deprecated attribute \"ignoreCase\" encountered in configuration.  Use \"caseSensitive\".");
+                ignoreCaseWarned = true;
+            }
+            // caseInsensitive = !"ignoreCase"
+            if (*ic == chLatin_t || *ic == chDigit_1)
+                result = false;
+            if (*ic == chLatin_f || *ic == chDigit_0)
+                result = true;
+        }
+        const XMLCh* ci = e->getAttributeNS(ns, caseSensitive);
+        if (ci && *ci) {
+            if (ic && *ic) {
+                logging::Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").warn("Attribute \"ignoreCase\" and \"caseSensitive\" should not be used in the same element.");
+            }
+            if (*ci == chLatin_t || *ci == chDigit_1) {
+                result =  true;
+            }
+            if (*ci == chLatin_f || *ci == chDigit_0) {
+                result =  false;
+            }
+        }
+    }
+    return result;
+}
+
 void XMLHelper::serialize(const DOMNode* n, std::string& buf, bool pretty)
 {
     static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };
diff --git a/xmltooling/util/XMLHelper.h b/xmltooling/util/XMLHelper.h
index 2fbbb3d..fd57f8a 100644
--- a/xmltooling/util/XMLHelper.h
+++ b/xmltooling/util/XMLHelper.h
@@ -333,6 +333,20 @@ namespace xmltooling {
             );
 
         /**
+         *
+         * Returns the value of the attribute "caseSensitive" (if present).  Also interogates
+         * the (deprecated) "ignoreCase" attribute, warning if it is encountered.
+         *
+         * @param e         element to examine (may be nullptr)
+         * @param defValue  default value to return
+         * @param ns        namespace of attribute
+         * @return whatever "caseSensitive" or "ignoreCase" specifies, or the specified default
+         */
+        static bool getCaseSensitive(
+            const xercesc::DOMElement* e, bool defValue, const XMLCh* ns=nullptr
+            );
+
+        /**
          * Serializes the DOM node provided into a buffer using UTF-8 encoding and
          * the default XML serializer available. No manipulation or formatting is applied.
          *
diff --git a/xmltoolingtest/data/IgnoreCase.xml b/xmltoolingtest/data/IgnoreCase.xml
new file mode 100644
index 0000000..7ba754e
--- /dev/null
+++ b/xmltoolingtest/data/IgnoreCase.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:Parent xmlns:test="test">
+  <test:IgnoreYes ignoreCase="t"/>
+  <test:IgnoreNo ignoreCase="0"/>
+  <test:CaseSensitiveYes caseSensitive="1"/>
+  <test:CaseSensitiveNo caseSensitive="f"/>
+  <test:Both ignoreCase="t" caseSensitive="t"/>
+  <test:Default/>
+</test:Parent>
diff --git a/xmltoolingtest/xmltoolingtest.h b/xmltoolingtest/xmltoolingtest.h
index c67423b..34699b0 100644
--- a/xmltoolingtest/xmltoolingtest.h
+++ b/xmltoolingtest/xmltoolingtest.h
@@ -79,7 +79,7 @@ public:
     }
 
     void testUnknown() {
-        ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
+        ifstream fs(data_path + "SimpleXMLObjectWithChildren.xml");
         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
         TS_ASSERT(doc!=nullptr);
 
@@ -107,7 +107,7 @@ public:
     }
 
     void testUnknownWithDocChange() {
-        ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");
+        ifstream fs(data_path + "SimpleXMLObjectWithChildren.xml");
         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
         TS_ASSERT(doc!=nullptr);
 
@@ -130,5 +130,38 @@ public:
 
         newDoc->release();
     }
+
+    void testHelper() {
+        ifstream fs(data_path + "IgnoreCase.xml");
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
+        TS_ASSERT(doc!=nullptr);
+        DOMElement* parent = doc->getDocumentElement();
+
+        static const XMLCh IgnoreYes[] =   UNICODE_LITERAL_9(I,g,n,o,r,e,Y,e,s);
+        static const XMLCh Test[] =   UNICODE_LITERAL_4(t,e,s,t);
+        DOMElement* el = XMLHelper::getFirstChildElement(parent, Test, IgnoreYes);
+        TS_ASSERT(!XMLHelper::getCaseSensitive(el, true));
+
+        static const XMLCh IgnoreNo[] =   UNICODE_LITERAL_8(I,g,n,o,r,e,N,o);
+        el = XMLHelper::getFirstChildElement(parent, Test, IgnoreNo);
+        TS_ASSERT(XMLHelper::getCaseSensitive(el, false));
+
+        static const XMLCh CaseSensitiveYes[] =   UNICODE_LITERAL_16(C,a,s,e,S,e,n,s,i,t,i,v,e,Y,e,s);
+        el = XMLHelper::getFirstChildElement(parent, Test, CaseSensitiveYes);
+        TS_ASSERT(XMLHelper::getCaseSensitive(el, false));
+
+        static const XMLCh CaseSensitiveNo[] =   UNICODE_LITERAL_15(C,a,s,e,S,e,n,s,i,t,i,v,e,N,o);
+        el = XMLHelper::getFirstChildElement(parent, Test, CaseSensitiveNo);
+        TS_ASSERT(!XMLHelper::getCaseSensitive(el, true));
+
+        static const XMLCh Both[] =   UNICODE_LITERAL_4(B,o,t,h);
+        el = XMLHelper::getFirstChildElement(parent, Test, Both);
+        TS_ASSERT(XMLHelper::getCaseSensitive(el, false));
+
+        static const XMLCh Default[] =   UNICODE_LITERAL_7(D,e,f,a,u,l,t);
+        el = XMLHelper::getFirstChildElement(parent, Test, Default);
+        TS_ASSERT(!XMLHelper::getCaseSensitive(el, false));
+        TS_ASSERT(XMLHelper::getCaseSensitive(el, true));
+    }
 };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-shibboleth/xmltooling.git



More information about the Pkg-shibboleth-devel mailing list