Mercurial > hg > orthanc
changeset 2331:a47d07b5b39f
Fix issue #56 (case-insensitive matching over accents)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Jul 2017 17:29:18 +0200 |
parents | 9c7a80c87ae9 |
children | 9ccd7f926c5b |
files | NEWS OrthancServer/Search/ListConstraint.cpp OrthancServer/Search/RangeConstraint.cpp OrthancServer/Search/ValueConstraint.cpp OrthancServer/Search/WildcardConstraint.cpp |
diffstat | 5 files changed, 60 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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(); }
--- 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 &&
--- 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); } } }
--- 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,