Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: add return value to ToUnicode/ToAscii stubs #10893

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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