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.

Conflicts:
	src/serialization/unicode.cpp
	src/tests/test_util.cpp
  • Loading branch information
cbeck88 authored and AI0867 committed Jun 4, 2014
1 parent 01fe3f5 commit 7cd9583
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/serialization/string_utils.cpp
Expand Up @@ -1065,8 +1065,7 @@ utf8_string lowercase(const utf8_string& s)
for(;itor != utf8_iterator::end(s); ++itor) {
ucs4char uchar = *itor;
// If wchar_t is less than 32 bits wide, we cannot apply towlower() to all codepoints
if(uchar <= static_cast<ucs4char>(std::numeric_limits<wchar_t>::max()) &&
uchar >= static_cast<ucs4char>(std::numeric_limits<wchar_t>::min()))
if(uchar <= static_cast<ucs4char>(std::numeric_limits<wchar_t>::max()))
uchar = towlower(static_cast<wchar_t>(uchar));
res += utils::ucs4char_to_string(uchar);
}
Expand Down
6 changes: 6 additions & 0 deletions src/tests/test_util.cpp
Expand Up @@ -16,6 +16,7 @@

#include <boost/test/unit_test.hpp>

#include "serialization/string_utils.hpp"
#include "util.hpp"

BOOST_AUTO_TEST_SUITE( util )
Expand Down Expand Up @@ -74,6 +75,11 @@ BOOST_AUTO_TEST_CASE( test_lexical_cast_default )
BOOST_CHECK( result6 >= 0.499 && result6 <= 0.511 );
}

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

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

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 7cd9583

Please sign in to comment.