Browse Source

src: fix windows-only build breakage

Commit af6af08 introduced a build error in a Windows-only code path in
src/node_url.cc.

Fix it by making the code a little nicer in general: const-ify the
`input` parameter to `ToASCII()` and `ToUnicode()`.

PR-URL: https://github.com/nodejs/node/pull/15724
Refs: https://github.com/nodejs/node/pull/15615
Refs: https://github.com/nodejs/node/pull/15723
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
v9.x-staging
Ben Noordhuis 7 years ago
committed by Luigi Pinca
parent
commit
d9d46e7757
  1. 22
      src/node_url.cc

22
src/node_url.cc

@ -573,30 +573,30 @@ static inline int NormalizePort(std::string scheme, int p) {
} }
#if defined(NODE_HAVE_I18N_SUPPORT) #if defined(NODE_HAVE_I18N_SUPPORT)
static inline bool ToUnicode(std::string* input, std::string* output) { static inline bool ToUnicode(const std::string& input, std::string* output) {
MaybeStackBuffer<char> buf; MaybeStackBuffer<char> buf;
if (i18n::ToUnicode(&buf, input->c_str(), input->length()) < 0) if (i18n::ToUnicode(&buf, input.c_str(), input.length()) < 0)
return false; return false;
output->assign(*buf, buf.length()); output->assign(*buf, buf.length());
return true; return true;
} }
static inline bool ToASCII(std::string* input, std::string* output) { static inline bool ToASCII(const std::string& input, std::string* output) {
MaybeStackBuffer<char> buf; MaybeStackBuffer<char> buf;
if (i18n::ToASCII(&buf, input->c_str(), input->length()) < 0) if (i18n::ToASCII(&buf, input.c_str(), input.length()) < 0)
return false; return false;
output->assign(*buf, buf.length()); output->assign(*buf, buf.length());
return true; return true;
} }
#else #else
// Intentional non-ops if ICU is not present. // Intentional non-ops if ICU is not present.
static inline bool ToUnicode(std::string* input, std::string* output) { static inline bool ToUnicode(const std::string& input, std::string* output) {
*output = *input; *output = input;
return true; return true;
} }
static inline bool ToASCII(std::string* input, std::string* output) { static inline bool ToASCII(const std::string& input, std::string* output) {
*output = *input; *output = input;
return true; return true;
} }
#endif #endif
@ -864,7 +864,7 @@ static url_host_type ParseHost(url_host* host,
PercentDecode(input, length, &decoded); PercentDecode(input, length, &decoded);
// Then we have to punycode toASCII // Then we have to punycode toASCII
if (!ToASCII(&decoded, &decoded)) if (!ToASCII(decoded, &decoded))
goto end; goto end;
// If any of the following characters are still present, we have to fail // If any of the following characters are still present, we have to fail
@ -881,7 +881,7 @@ static url_host_type ParseHost(url_host* host,
goto end; goto end;
// If the unicode flag is set, run the result through punycode ToUnicode // If the unicode flag is set, run the result through punycode ToUnicode
if (unicode && !ToUnicode(&decoded, &decoded)) if (unicode && !ToUnicode(decoded, &decoded))
goto end; goto end;
// It's not an IPv4 or IPv6 address, it must be a domain // It's not an IPv4 or IPv6 address, it must be a domain
@ -2124,7 +2124,7 @@ std::string URL::ToFilePath() const {
if ((context_.flags & URL_FLAGS_HAS_HOST) && if ((context_.flags & URL_FLAGS_HAS_HOST) &&
context_.host.length() > 0) { context_.host.length() > 0) {
std::string unicode_host; std::string unicode_host;
if (!ToUnicode(&context_.host, &unicode_host)) { if (!ToUnicode(context_.host, &unicode_host)) {
return ""; return "";
} }
return "\\\\" + unicode_host + decoded_path; return "\\\\" + unicode_host + decoded_path;

Loading…
Cancel
Save