# HG changeset patch # User Sebastien Jodogne # Date 1446131339 -3600 # Node ID 9ead18ef460a09b2c16b52b9133160a5476a607e # Parent f7014cca73c7bea98b6344c13782aee1fbc18864 escape diff -r f7014cca73c7 -r 9ead18ef460a OrthancServer/Search/LookupIdentifierQuery.cpp --- 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); } diff -r f7014cca73c7 -r 9ead18ef460a OrthancServer/Search/LookupIdentifierQuery.h --- a/OrthancServer/Search/LookupIdentifierQuery.h Thu Oct 29 12:45:20 2015 +0100 +++ b/OrthancServer/Search/LookupIdentifierQuery.h Thu Oct 29 16:08:59 2015 +0100 @@ -129,8 +129,6 @@ ResourceType level_; Constraints constraints_; - static std::string NormalizeIdentifier(const std::string& value); - public: LookupIdentifierQuery(ResourceType level) : level_(level) { @@ -178,6 +176,8 @@ ResourceType level, const DicomMap& map); + static std::string NormalizeIdentifier(const std::string& value); + void Print(std::ostream& s) const; }; } diff -r f7014cca73c7 -r 9ead18ef460a UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Thu Oct 29 12:45:20 2015 +0100 +++ b/UnitTestsSources/ServerIndexTests.cpp Thu Oct 29 16:08:59 2015 +0100 @@ -828,3 +828,10 @@ context.Stop(); db.Close(); } + + +TEST(LookupIdentifierQuery, NormalizeIdentifier) +{ + ASSERT_EQ("H^L.LO", LookupIdentifierQuery::NormalizeIdentifier(" Hé^l.LO %_ ")); + ASSERT_EQ("1.2.840.113619.2.176.2025", LookupIdentifierQuery::NormalizeIdentifier(" 1.2.840.113619.2.176.2025 ")); +}