Skip to content

Commit

Permalink
Replace strcasecmp() with isUTF8() (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
rockdaboot committed Feb 10, 2024
1 parent 4f09bcf commit 0fdbd1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 0 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ AC_CHECK_FUNCS([strndup clock_gettime fmemopen nl_langinfo])
# check for dirent.h
AC_HEADER_DIRENT

# strings.h may not exist on WIN32
AC_CHECK_HEADERS([strings.h])

# Override the template file name of the generated .pc file, so that there
# is no need to rename the template file when the API version changes.
AC_CONFIG_FILES([Makefile
Expand Down
13 changes: 9 additions & 4 deletions src/psl.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ typedef SSIZE_T ssize_t;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <ctype.h>
#include <time.h>
#include <errno.h>
Expand Down Expand Up @@ -333,6 +330,14 @@ static int suffix_init(psl_entry_t *suffix, const char *rule, size_t length)
return 0;
}

/* Avoid using strcasecmp() or _stricmp() */
static int isUTF8(const char *s) {
return (s[0] == 'u' || s[0] == 'U')
&& (s[1] == 't' || s[1] == 'T')
&& (s[2] == 'f' || s[2] == 'F')
&& s[3] == '-' && s[4] == 0;
}

#if !defined(WITH_LIBIDN) && !defined(WITH_LIBIDN2) && !defined(WITH_LIBICU)
/*
* When configured without runtime IDNA support (./configure --disable-runtime), we need a pure ASCII
Expand Down Expand Up @@ -1827,7 +1832,7 @@ psl_error_t psl_str_to_utf8lower(const char *str, const char *encoding PSL_UNUSE
}

/* convert to UTF-8 */
if (strcasecmp(encoding, "utf-8")) {
if (!isUTF8(encoding)) {
iconv_t cd = iconv_open("utf-8", encoding);

if (cd != (iconv_t)-1) {
Expand Down

0 comments on commit 0fdbd1b

Please sign in to comment.