Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3642f35

Browse filesBrowse files
poiruItalo A. Casas
authored andcommitted
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 PR-URL: #10893 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
1 parent aa4b028 commit 3642f35
Copy full SHA for 3642f35

File tree

Expand file treeCollapse file tree

1 file changed

+29
-29
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-29
lines changed
Open diff view settings
Collapse file

‎src/node_url.cc‎

Copy file name to clipboardExpand all lines: src/node_url.cc
+29-29Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,50 +96,50 @@ using v8::Value;
9696
namespace url {
9797

9898
#if defined(NODE_HAVE_I18N_SUPPORT)
99-
static int ToUnicode(std::string* input, std::string* output) {
99+
static bool ToUnicode(std::string* input, std::string* output) {
100100
MaybeStackBuffer<char> buf;
101101
if (i18n::ToUnicode(&buf, input->c_str(), input->length()) < 0)
102-
return -1;
102+
return false;
103103
output->assign(*buf, buf.length());
104-
return 0;
104+
return true;
105105
}
106106

107-
static int ToASCII(std::string* input, std::string* output) {
107+
static bool ToASCII(std::string* input, std::string* output) {
108108
MaybeStackBuffer<char> buf;
109109
if (i18n::ToASCII(&buf, input->c_str(), input->length()) < 0)
110-
return -1;
110+
return false;
111111
output->assign(*buf, buf.length());
112-
return 0;
112+
return true;
113113
}
114114

115115
// Unfortunately there's not really a better way to do this.
116116
// Iterate through each encoded codepoint and verify that
117117
// it is a valid unicode codepoint.
118-
static int IsValidUTF8(std::string* input) {
118+
static bool IsValidUTF8(std::string* input) {
119119
const char* p = input->c_str();
120120
int32_t len = input->length();
121121
for (int32_t i = 0; i < len;) {
122122
UChar32 c;
123123
U8_NEXT_UNSAFE(p, i, c);
124124
if (!U_IS_UNICODE_CHAR(c))
125-
return -1;
125+
return false;
126126
}
127-
return 0;
127+
return true;
128128
}
129129
#else
130130
// Intentional non-ops if ICU is not present.
131-
static int ToUnicode(std::string* input, std::string* output) {
132-
output->reserve(input->length());
133-
*output = input->c_str();
131+
static bool ToUnicode(std::string* input, std::string* output) {
132+
*output = *input;
133+
return true;
134134
}
135135

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

141-
static int IsValidUTF8(std::string* input) {
142-
return 0;
141+
static bool IsValidUTF8(std::string* input) {
142+
return true;
143143
}
144144
#endif
145145

@@ -381,11 +381,11 @@ namespace url {
381381
// If there are any invalid UTF8 byte sequences, we have to fail.
382382
// Unfortunately this means iterating through the string and checking
383383
// each decoded codepoint.
384-
if (IsValidUTF8(&decoded) < 0)
384+
if (!IsValidUTF8(&decoded))
385385
goto end;
386386

387387
// Then we have to punycode toASCII
388-
if (ToASCII(&decoded, &decoded) < 0)
388+
if (!ToASCII(&decoded, &decoded))
389389
goto end;
390390

391391
// If any of the following characters are still present, we have to fail
@@ -405,7 +405,7 @@ namespace url {
405405
goto end;
406406

407407
// If the unicode flag is set, run the result through punycode ToUnicode
408-
if (unicode && ToUnicode(&decoded, &decoded) < 0)
408+
if (unicode && !ToUnicode(&decoded, &decoded))
409409
goto end;
410410

411411
// It's not an IPv4 or IPv6 address, it must be a domain
@@ -499,17 +499,17 @@ namespace url {
499499
return host->type;
500500
}
501501

502-
static int ParseHost(std::string* input,
503-
std::string* output,
504-
bool unicode = false) {
502+
static bool ParseHost(std::string* input,
503+
std::string* output,
504+
bool unicode = false) {
505505
if (input->length() == 0)
506-
return 0;
506+
return true;
507507
url_host host{{""}, HOST_TYPE_DOMAIN};
508508
ParseHost(&host, input->c_str(), input->length(), unicode);
509509
if (host.type == HOST_TYPE_FAILED)
510-
return -1;
510+
return false;
511511
WriteHost(&host, output);
512-
return 0;
512+
return true;
513513
}
514514

515515
static inline void Copy(Isolate* isolate,
@@ -996,7 +996,7 @@ namespace url {
996996
if (special && buffer.size() == 0)
997997
URL_FAILED()
998998
SET_HAVE_HOST()
999-
if (ParseHost(&buffer, &url.host) < 0)
999+
if (!ParseHost(&buffer, &url.host))
10001000
URL_FAILED()
10011001
buffer.clear();
10021002
state = kPort;
@@ -1011,7 +1011,7 @@ namespace url {
10111011
if (special && buffer.size() == 0)
10121012
URL_FAILED()
10131013
SET_HAVE_HOST()
1014-
if (ParseHost(&buffer, &url.host) < 0)
1014+
if (!ParseHost(&buffer, &url.host))
10151015
URL_FAILED()
10161016
buffer.clear();
10171017
state = kPathStart;
@@ -1161,7 +1161,7 @@ namespace url {
11611161
} else {
11621162
if (buffer != "localhost") {
11631163
SET_HAVE_HOST()
1164-
if (ParseHost(&buffer, &url.host) < 0)
1164+
if (!ParseHost(&buffer, &url.host))
11651165
URL_FAILED()
11661166
}
11671167
buffer.clear();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.