diff options
-rw-r--r-- | lib/misc.c | 12 | ||||
-rw-r--r-- | tests/check.c | 2 | ||||
-rw-r--r-- | tests/check_util.c | 9 |
3 files changed, 19 insertions, 4 deletions
@@ -304,14 +304,18 @@ void http_encode( char *s ) for( i = j = 0; t[i]; i ++, j ++ ) { - if( !isalnum( t[i] ) && !strchr( "._-~", t[i] ) ) + /* Warning: isalnum() is locale-aware, so don't use it here! */ + if( ( t[i] >= 'A' && t[i] <= 'Z' ) || + ( t[i] >= 'a' && t[i] <= 'z' ) || + ( t[i] >= '0' && t[i] <= '9' ) || + strchr( "._-~", t[i] ) ) { - sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] ); - j += 2; + s[j] = t[i]; } else { - s[j] = t[i]; + sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] ); + j += 2; } } s[j] = 0; diff --git a/tests/check.c b/tests/check.c index e42f1255..601d9726 100644 --- a/tests/check.c +++ b/tests/check.c @@ -2,6 +2,7 @@ #include <glib.h> #include <gmodule.h> #include <check.h> +#include <locale.h> #include "bitlbee.h" #include "testsuite.h" @@ -91,6 +92,7 @@ int main (int argc, char **argv) g_option_context_free(pc); log_init(); + setlocale(LC_CTYPE, ""); if (verbose) { log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE ); diff --git a/tests/check_util.c b/tests/check_util.c index b00d645b..c323241e 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -160,6 +160,14 @@ START_TEST(test_word_wrap) } END_TEST +START_TEST(test_http_encode) + char s[80]; + + strcpy( s, "ee\xc3""\xab""ee!!..." ); + http_encode( s ); + fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0 ); +END_TEST + Suite *util_suite (void) { Suite *s = suite_create("Util"); @@ -173,5 +181,6 @@ Suite *util_suite (void) tcase_add_test (tc_core, test_set_url_username); tcase_add_test (tc_core, test_set_url_username_pwd); tcase_add_test (tc_core, test_word_wrap); + tcase_add_test (tc_core, test_http_encode); return s; } |