diff OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp @ 4333:a85e74235a78

fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Nov 2020 06:57:23 +0100
parents 50b0c69b653a
children 4301722b3225
line wrap: on
line diff
--- a/OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp	Wed Nov 25 21:42:50 2020 +0100
+++ b/OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp	Fri Nov 27 06:57:23 2020 +0100
@@ -297,6 +297,17 @@
   }
 
 
+  static void RemoveSurroundingQuotes(std::string& value)
+  {
+    if (value.size() >= 2 &&
+        value[0] == '"' &&
+        value[value.size() - 1] == '"')
+    {
+      value = value.substr(1, value.size() - 2);
+    }
+  }
+  
+
   bool MultipartStreamReader::ParseMultipartContentType(std::string& contentType,
                                                         std::string& subType,
                                                         std::string& boundary,
@@ -331,6 +342,10 @@
         if (boost::iequals("boundary", Toolbox::StripSpaces(items[0])))
         {
           boundary = Toolbox::StripSpaces(items[1]);
+
+          // https://bugs.orthanc-server.com/show_bug.cgi?id=190
+          RemoveSurroundingQuotes(boundary);
+          
           valid = !boundary.empty();
         }
         else if (boost::iequals("type", Toolbox::StripSpaces(items[0])))
@@ -340,12 +355,7 @@
 
           // https://bitbucket.org/sjodogne/orthanc/issues/54/decide-what-to-do-wrt-quoting-of-multipart
           // https://tools.ietf.org/html/rfc7231#section-3.1.1.1
-          if (subType.size() >= 2 &&
-              subType[0] == '"' &&
-              subType[subType.size() - 1] == '"')
-          {
-            subType = subType.substr(1, subType.size() - 2);
-          }
+          RemoveSurroundingQuotes(subType);
         }
       }
     }