# HG changeset patch # User Sebastien Jodogne # Date 1500046158 -7200 # Node ID a47d07b5b39f418d2f4e9381509584c2fc1c3330 # Parent 9c7a80c87ae975e0bba626436de5a49d35fbb1a3 Fix issue #56 (case-insensitive matching over accents) diff -r 9c7a80c87ae9 -r a47d07b5b39f NEWS --- a/NEWS Fri Jul 14 16:34:16 2017 +0200 +++ b/NEWS Fri Jul 14 17:29:18 2017 +0200 @@ -48,6 +48,7 @@ * Fix issue 49 (worklists: accentuated characters are removed from C-Find responses) * Fix issue 55 (modification/anonymization of tags that might break the database model now requires the "Force" parameter to be set to "true" in the query) +* Fix issue 56 (case-insensitive matching over accents) * Fix Debian #865606 (orthanc FTBFS with libdcmtk-dev 3.6.1~20170228-2) * Fix XSS inside DICOM in Orthanc Explorer (as reported by Victor Pasnkel, Morphus Labs) * Upgrade forthcoming DCMTK 3.6.1 to snapshot 20170228 diff -r 9c7a80c87ae9 -r a47d07b5b39f OrthancServer/Search/ListConstraint.cpp --- a/OrthancServer/Search/ListConstraint.cpp Fri Jul 14 16:34:16 2017 +0200 +++ b/OrthancServer/Search/ListConstraint.cpp Fri Jul 14 17:29:18 2017 +0200 @@ -45,9 +45,7 @@ } else { - std::string s = value; - Toolbox::ToUpperCase(s); - allowedValues_.insert(s); + allowedValues_.insert(Toolbox::ToUpperCaseWithAccents(value)); } } @@ -67,14 +65,18 @@ bool ListConstraint::Match(const std::string& value) const { - std::string v = value; - - if (!isCaseSensitive_) + std::string s; + + if (isCaseSensitive_) { - Toolbox::ToUpperCase(v); + s = value; + } + else + { + s = Toolbox::ToUpperCaseWithAccents(value); } - return allowedValues_.find(v) != allowedValues_.end(); + return allowedValues_.find(s) != allowedValues_.end(); } diff -r 9c7a80c87ae9 -r a47d07b5b39f OrthancServer/Search/RangeConstraint.cpp --- a/OrthancServer/Search/RangeConstraint.cpp Fri Jul 14 16:34:16 2017 +0200 +++ b/OrthancServer/Search/RangeConstraint.cpp Fri Jul 14 17:29:18 2017 +0200 @@ -41,14 +41,17 @@ RangeConstraint::RangeConstraint(const std::string& lower, const std::string& upper, bool isCaseSensitive) : - lower_(lower), - upper_(upper), isCaseSensitive_(isCaseSensitive) { - if (!isCaseSensitive_) + if (isCaseSensitive_) { - Toolbox::ToUpperCase(lower_); - Toolbox::ToUpperCase(upper_); + lower_ = lower; + upper_ = upper; + } + else + { + lower_ = Toolbox::ToUpperCaseWithAccents(lower); + upper_ = Toolbox::ToUpperCaseWithAccents(upper); } } @@ -70,11 +73,15 @@ bool RangeConstraint::Match(const std::string& value) const { - std::string v = value; + std::string v; - if (!isCaseSensitive_) + if (isCaseSensitive_) { - Toolbox::ToUpperCase(v); + v = value; + } + else + { + v = Toolbox::ToUpperCaseWithAccents(value); } if (lower_.size() == 0 && diff -r 9c7a80c87ae9 -r a47d07b5b39f OrthancServer/Search/ValueConstraint.cpp --- a/OrthancServer/Search/ValueConstraint.cpp Fri Jul 14 16:34:16 2017 +0200 +++ b/OrthancServer/Search/ValueConstraint.cpp Fri Jul 14 17:29:18 2017 +0200 @@ -42,12 +42,15 @@ { ValueConstraint::ValueConstraint(const std::string& value, bool isCaseSensitive) : - value_(value), isCaseSensitive_(isCaseSensitive) { - if (!isCaseSensitive) + if (isCaseSensitive) { - Toolbox::ToUpperCase(value_); + value_ = value; + } + else + { + value_ = Toolbox::ToUpperCaseWithAccents(value); } } @@ -66,9 +69,7 @@ } else { - std::string v; - Toolbox::ToUpperCase(v, value); - return value_ == v; + return value_ == Toolbox::ToUpperCaseWithAccents(value); } } } diff -r 9c7a80c87ae9 -r a47d07b5b39f OrthancServer/Search/WildcardConstraint.cpp --- a/OrthancServer/Search/WildcardConstraint.cpp Fri Jul 14 16:34:16 2017 +0200 +++ b/OrthancServer/Search/WildcardConstraint.cpp Fri Jul 14 17:29:18 2017 +0200 @@ -42,6 +42,24 @@ { boost::regex pattern_; std::string wildcard_; + bool isCaseSensitive_; + + PImpl(const std::string& wildcard, + bool isCaseSensitive) + { + isCaseSensitive_ = isCaseSensitive; + + if (isCaseSensitive) + { + wildcard_ = wildcard; + } + else + { + wildcard_ = Toolbox::ToUpperCaseWithAccents(wildcard); + } + + pattern_ = boost::regex(Toolbox::WildcardToRegularExpression(wildcard_)); + } }; @@ -53,25 +71,20 @@ WildcardConstraint::WildcardConstraint(const std::string& wildcard, bool isCaseSensitive) : - pimpl_(new PImpl) + pimpl_(new PImpl(wildcard, isCaseSensitive)) { - pimpl_->wildcard_ = wildcard; - - std::string re = Toolbox::WildcardToRegularExpression(wildcard); - - if (isCaseSensitive) - { - pimpl_->pattern_ = boost::regex(re); - } - else - { - pimpl_->pattern_ = boost::regex(re, boost::regex::icase /* case insensitive search */); - } } bool WildcardConstraint::Match(const std::string& value) const { - return boost::regex_match(value, pimpl_->pattern_); + if (pimpl_->isCaseSensitive_) + { + return boost::regex_match(value, pimpl_->pattern_); + } + else + { + return boost::regex_match(Toolbox::ToUpperCaseWithAccents(value), pimpl_->pattern_); + } } void WildcardConstraint::Setup(LookupIdentifierQuery& lookup,