https://issues.shibboleth.net/jira/browse/SSPCPP-472
[shibboleth/sp.git] / shibsp / attribute / ExtensibleAttribute.cpp
index 41a38a5..2d4fe54 100644 (file)
@@ -29,6 +29,8 @@
 #include "attribute/ExtensibleAttribute.h"
 #include "util/SPConstants.h"
 
+#include <boost/algorithm/string/trim.hpp>
+
 using namespace shibsp;
 using namespace xmltooling;
 using namespace std;
@@ -103,20 +105,20 @@ const vector<string>& ExtensibleAttribute::getSerializedValues() const
                 string& processed = m_serialized.back();
 
                 string::size_type i=0,start=0;
-                while (start!=string::npos && start<msg.length() && (i=msg.find("$",start))!=string::npos) {
+                while (start != string::npos && start < msg.length() && (i = msg.find("$",start)) != string::npos) {
                     if (i>start)
-                        processed += msg.substr(start,i-start); // append everything in between
-                    start=i+1;                                  // move start to the beginning of the token name
-                    i=msg.find_first_not_of(legal,start);       // find token delimiter
-                    if (i==start) {                             // append a non legal character
-                       processed+=msg[start++];
+                        processed += msg.substr(start, i-start);    // append everything in between
+                    start = i+1;                                    // move start to the beginning of the token name
+                    i = msg.find_first_not_of(legal, start);        // find token delimiter
+                    if (i == start) {                               // append a non legal character
+                       processed += msg[start++];
                        continue;
                     }
                     
-                    string tag = msg.substr(start,(i==string::npos) ? i : i-start);
+                    string tag = msg.substr(start, (i==string::npos) ? i : i-start);
                     if (tag == "_string" && val.string()) {
                         processed += val.string();
-                        start=i;
+                        start = i;
                     }
                     else {
                         DDF child = val.getmember(tag.c_str());
@@ -124,11 +126,12 @@ const vector<string>& ExtensibleAttribute::getSerializedValues() const
                             processed += child.string();
                         else if (child.isstruct() && child["_string"].string())
                             processed += child["_string"].string();
-                        start=i;
+                        start = i;
                     }
                 }
-                if (start!=string::npos && start<msg.length())
+                if (start != string::npos && start < msg.length())
                     processed += msg.substr(start,i);    // append rest of string
+                boost::trim(processed);
 
                 val = m_obj.first().next();
             }