https://issues.shibboleth.net/jira/browse/SSPCPP-472
[shibboleth/sp.git] / plugins / TransformAttributeResolver.cpp
index f620dc0..6b4bf7b 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <algorithm>
 #include <boost/shared_ptr.hpp>
+#include <boost/algorithm/string/trim.hpp>
 #include <boost/tuple/tuple.hpp>
 #include <shibsp/exceptions.h>
 #include <shibsp/SessionCache.h>
@@ -223,8 +224,8 @@ void TransformAttributeResolver::resolveAttributes(ResolutionContext& ctx) const
                 m_log.debug("applying transform from source attribute (%s) to dest attribute (%s)", m_source.c_str(), r->get<0>().c_str());
 
             for (size_t i = 0; i < (*a)->valueCount(); ++i) {
-                auto_arrayptr<XMLCh> srcval(fromUTF8((*a)->getSerializedValues()[i].c_str()));
                 try {
+                    auto_arrayptr<XMLCh> srcval(fromUTF8((*a)->getSerializedValues()[i].c_str()));
                     XMLCh* destval = r->get<1>()->replace(srcval.get(), r->get<2>());
                     if (destval) {
                         auto_arrayptr<char> narrow(toUTF8(destval));
@@ -232,10 +233,12 @@ void TransformAttributeResolver::resolveAttributes(ResolutionContext& ctx) const
                         if (dest) {
                             // Modify in place.
                             dest->getValues()[i] = narrow.get();
+                            trim(dest->getValues()[i]);
                         }
                         else {
                             // Add to new object.
                             destwrapper->getValues().push_back(narrow.get());
+                            trim(destwrapper->getValues().back());
                         }
                     }
                 }