diff OrthancServer/Search/LookupIdentifierQuery.cpp @ 1764:9ead18ef460a

escape
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Oct 2015 16:08:59 +0100
parents 318c2e83c2bd
children b1291df2f780
line wrap: on
line diff
--- a/OrthancServer/Search/LookupIdentifierQuery.cpp	Thu Oct 29 12:45:20 2015 +0100
+++ b/OrthancServer/Search/LookupIdentifierQuery.cpp	Thu Oct 29 16:08:59 2015 +0100
@@ -171,9 +171,27 @@
 
   std::string LookupIdentifierQuery::NormalizeIdentifier(const std::string& value)
   {
-    std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value));
-    Toolbox::ToUpperCase(s);
-    return s;
+    std::string t;
+    t.reserve(value.size());
+
+    for (size_t i = 0; i < value.size(); i++)
+    {
+      if (value[i] == '%' ||
+          value[i] == '_')
+      {
+        t.push_back(' ');  // These characters might break wildcard queries in SQL
+      }
+      else if (isascii(value[i]) &&
+               !iscntrl(value[i]) &&
+               (!isspace(value[i]) || value[i] == ' '))
+      {
+        t.push_back(value[i]);
+      }
+    }
+
+    Toolbox::ToUpperCase(t);
+
+    return Toolbox::StripSpaces(t);
   }