From f6940dfa4627301bbd1a24530ac3f4fe3fe8494c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 4 May 2016 20:56:04 +0200 Subject: src: don't use locale-sensitive strcasecmp() strcasecmp() is affected by the current locale as configured through e.g. the LC_ALL environment variable and the setlocale() libc function. It can result in unpredictable results across systems so replace it with a function that isn't susceptible to that. PR-URL: https://github.com/nodejs/node/pull/6582 Reviewed-By: Anna Henningsen Reviewed-By: Fedor Indutny Reviewed-By: James M Snell --- src/util-inl.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/util-inl.h') diff --git a/src/util-inl.h b/src/util-inl.h index 7ff6e51937..355dfcdbee 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -203,7 +203,19 @@ void SwapBytes(uint16_t* dst, const uint16_t* src, size_t buflen) { dst[i] = (src[i] << 8) | (src[i] >> 8); } +char ToLower(char c) { + return c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c; +} +bool StringEqualNoCase(const char* a, const char* b) { + do { + if (*a == '\0') + return *b == '\0'; + if (*b == '\0') + return *a == '\0'; + } while (ToLower(*a++) == ToLower(*b++)); + return false; +} } // namespace node -- cgit v1.2.1