Skip to content

Commit

Permalink
url: add return value to ToUnicode/ToAscii stubs
Browse files Browse the repository at this point in the history
This fixes compilation errors like:

  node\src\node_url.cc(134) : error C4716: 'node::url::ToUnicode': must
  return a value

PR-URL: nodejs#10893
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michal Zasso <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
  • Loading branch information
poiru authored and italoacasas committed Jan 25, 2017
1 parent 104c771 commit 71770b4
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,50 +96,50 @@ 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<char> 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<char> 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) {
output->reserve(input->length());
*output = input->c_str();
static bool ToUnicode(std::string* input, std::string* output) {
*output = *input;
return true;
}

static int ToASCII(std::string* input, std::string* output) {
output->reserve(input->length());
*output = input->c_str();
static bool ToASCII(std::string* input, std::string* output) {
*output = *input;
return true;
}

static int IsValidUTF8(std::string* input) {
return 0;
static bool IsValidUTF8(std::string* input) {
return true;
}
#endif

Expand Down Expand Up @@ -381,11 +381,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
Expand All @@ -405,7 +405,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
Expand Down Expand Up @@ -499,17 +499,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,
Expand Down Expand Up @@ -996,7 +996,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;
Expand All @@ -1011,7 +1011,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;
Expand Down Expand Up @@ -1161,7 +1161,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();
Expand Down

0 comments on commit 71770b4

Please sign in to comment.