Skip to content

Commit

Permalink
Fix utf8::lowercase (bug #22139)
Browse files Browse the repository at this point in the history
As ucs4::char is unsigned, we don't need to compare against the min value of
the type. Worse, we cast the (possibly signed) min value to ucs4::char, which
on plenty of systems, results in 2^31, excluding all valid unicode codepoints.

Fix by gfgtdf.
Patch by iceiceice. (PR #189)
Commit message by ai0867.
  • Loading branch information
cbeck88 authored and AI0867 committed Jun 4, 2014
1 parent c73f236 commit b650809
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/serialization/unicode.cpp
Expand Up @@ -260,8 +260,7 @@ utf8::string lowercase(const utf8::string& s)
for(;itor != utf8::iterator::end(s); ++itor) {
ucs4::char_t uchar = *itor;
// If wchar_t is less than 32 bits wide, we cannot apply towlower() to all codepoints
if(uchar <= static_cast<ucs4::char_t>(std::numeric_limits<wchar_t>::max()) &&
uchar >= static_cast<ucs4::char_t>(std::numeric_limits<wchar_t>::min()))
if(uchar <= static_cast<ucs4::char_t>(std::numeric_limits<wchar_t>::max()))
uchar = towlower(static_cast<wchar_t>(uchar));
res += unicode_cast<utf8::string>(uchar);
}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/test_util.cpp
Expand Up @@ -18,6 +18,8 @@

#include "util.hpp"

#include "serialization/unicode.hpp"

#include <boost/cstdint.hpp>

BOOST_AUTO_TEST_SUITE( util )
Expand Down Expand Up @@ -140,6 +142,11 @@ BOOST_AUTO_TEST_CASE( test_count_leading_ones )
BOOST_CHECK( count_leading_ones(static_cast<boost::uint16_t>(54321)) == 2 );
}

BOOST_AUTO_TEST_CASE( test_lowercase )
{
BOOST_CHECK_EQUAL ( utf8::lowercase("FOO") , "foo" );
}

/* vim: set ts=4 sw=4: */

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b650809

Please sign in to comment.