From 68820471a2a1f6b90b87120f8800cf2973445246 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Thu, 19 Jan 2017 08:38:50 +0200 Subject: [PATCH 1/3] url: add return value to ToUnicode/ToAscii stubs This fixes compilation errors like: node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must return a value --- src/node_url.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/node_url.cc b/src/node_url.cc index 538126eb872b2a..6304f912d40426 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -131,11 +131,13 @@ namespace url { static int ToUnicode(std::string* input, std::string* output) { output->reserve(input->length()); *output = input->c_str(); + return 0; } static int ToASCII(std::string* input, std::string* output) { output->reserve(input->length()); *output = input->c_str(); + return 0; } static int IsValidUTF8(std::string* input) { From 74af4eb6408fda2711e5b53e2195d1be9b7b8c56 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Thu, 19 Jan 2017 19:04:25 +0200 Subject: [PATCH 2/3] url: convert int return types to bool --- src/node_url.cc | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index 6304f912d40426..d83b6b4e60c60a 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -96,52 +96,52 @@ using v8::Value; namespace url { #if defined(NODE_HAVE_I18N_SUPPORT) - static int ToUnicode(std::string* input, std::string* output) { + static bool ToUnicode(std::string* input, std::string* output) { MaybeStackBuffer buf; if (i18n::ToUnicode(&buf, input->c_str(), input->length()) < 0) - return -1; + return false; output->assign(*buf, buf.length()); - return 0; + return true; } - static int ToASCII(std::string* input, std::string* output) { + static bool ToASCII(std::string* input, std::string* output) { MaybeStackBuffer buf; if (i18n::ToASCII(&buf, input->c_str(), input->length()) < 0) - return -1; + return false; output->assign(*buf, buf.length()); - return 0; + return true; } // Unfortunately there's not really a better way to do this. // Iterate through each encoded codepoint and verify that // it is a valid unicode codepoint. - static int IsValidUTF8(std::string* input) { + static bool IsValidUTF8(std::string* input) { const char* p = input->c_str(); int32_t len = input->length(); for (int32_t i = 0; i < len;) { UChar32 c; U8_NEXT_UNSAFE(p, i, c); if (!U_IS_UNICODE_CHAR(c)) - return -1; + return false; } - return 0; + return true; } #else // Intentional non-ops if ICU is not present. - static int ToUnicode(std::string* input, std::string* output) { + static bool ToUnicode(std::string* input, std::string* output) { output->reserve(input->length()); *output = input->c_str(); - return 0; + return true; } - static int ToASCII(std::string* input, std::string* output) { + static bool ToASCII(std::string* input, std::string* output) { output->reserve(input->length()); *output = input->c_str(); - return 0; + return true; } - static int IsValidUTF8(std::string* input) { - return 0; + static bool IsValidUTF8(std::string* input) { + return true; } #endif @@ -383,11 +383,11 @@ namespace url { // If there are any invalid UTF8 byte sequences, we have to fail. // Unfortunately this means iterating through the string and checking // each decoded codepoint. - if (IsValidUTF8(&decoded) < 0) + if (!IsValidUTF8(&decoded)) goto end; // Then we have to punycode toASCII - if (ToASCII(&decoded, &decoded) < 0) + if (!ToASCII(&decoded, &decoded)) goto end; // If any of the following characters are still present, we have to fail @@ -407,7 +407,7 @@ namespace url { goto end; // If the unicode flag is set, run the result through punycode ToUnicode - if (unicode && ToUnicode(&decoded, &decoded) < 0) + if (unicode && !ToUnicode(&decoded, &decoded)) goto end; // It's not an IPv4 or IPv6 address, it must be a domain @@ -501,17 +501,17 @@ namespace url { return host->type; } - static int ParseHost(std::string* input, - std::string* output, - bool unicode = false) { + static bool ParseHost(std::string* input, + std::string* output, + bool unicode = false) { if (input->length() == 0) - return 0; + return true; url_host host{{""}, HOST_TYPE_DOMAIN}; ParseHost(&host, input->c_str(), input->length(), unicode); if (host.type == HOST_TYPE_FAILED) - return -1; + return false; WriteHost(&host, output); - return 0; + return true; } static inline void Copy(Isolate* isolate, @@ -998,7 +998,7 @@ namespace url { if (special && buffer.size() == 0) URL_FAILED() SET_HAVE_HOST() - if (ParseHost(&buffer, &url.host) < 0) + if (!ParseHost(&buffer, &url.host)) URL_FAILED() buffer.clear(); state = kPort; @@ -1013,7 +1013,7 @@ namespace url { if (special && buffer.size() == 0) URL_FAILED() SET_HAVE_HOST() - if (ParseHost(&buffer, &url.host) < 0) + if (!ParseHost(&buffer, &url.host)) URL_FAILED() buffer.clear(); state = kPathStart; @@ -1163,7 +1163,7 @@ namespace url { } else { if (buffer != "localhost") { SET_HAVE_HOST() - if (ParseHost(&buffer, &url.host) < 0) + if (!ParseHost(&buffer, &url.host)) URL_FAILED() } buffer.clear(); From a8438acdf60bfe12be9c8d886958640749a2f10b Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Thu, 19 Jan 2017 19:07:52 +0200 Subject: [PATCH 3/3] url: simplify string copying --- src/node_url.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index d83b6b4e60c60a..92cb8efbb84389 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -129,14 +129,12 @@ namespace url { #else // Intentional non-ops if ICU is not present. static bool ToUnicode(std::string* input, std::string* output) { - output->reserve(input->length()); - *output = input->c_str(); + *output = *input; return true; } static bool ToASCII(std::string* input, std::string* output) { - output->reserve(input->length()); - *output = input->c_str(); + *output = *input; return true; }