From d9d46e7757be0b76ab53c83e489e347511b10e97 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 2 Oct 2017 09:07:10 +0200 Subject: [PATCH] src: fix windows-only build breakage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Gibson Fahnestock Reviewed-By: Anna Henningsen Reviewed-By: Tobias Nießen --- src/node_url.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index 157adc3f63..3dd89d7483 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -573,30 +573,30 @@ static inline int NormalizePort(std::string scheme, int p) { } #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 buf; - if (i18n::ToUnicode(&buf, input->c_str(), input->length()) < 0) + if (i18n::ToUnicode(&buf, input.c_str(), input.length()) < 0) return false; output->assign(*buf, buf.length()); return true; } -static inline bool ToASCII(std::string* input, std::string* output) { +static inline bool ToASCII(const std::string& input, std::string* output) { MaybeStackBuffer buf; - if (i18n::ToASCII(&buf, input->c_str(), input->length()) < 0) + if (i18n::ToASCII(&buf, input.c_str(), input.length()) < 0) return false; output->assign(*buf, buf.length()); return true; } #else // Intentional non-ops if ICU is not present. -static inline bool ToUnicode(std::string* input, std::string* output) { - *output = *input; +static inline bool ToUnicode(const std::string& input, std::string* output) { + *output = input; return true; } -static inline bool ToASCII(std::string* input, std::string* output) { - *output = *input; +static inline bool ToASCII(const std::string& input, std::string* output) { + *output = input; return true; } #endif @@ -864,7 +864,7 @@ static url_host_type ParseHost(url_host* host, PercentDecode(input, length, &decoded); // Then we have to punycode toASCII - if (!ToASCII(&decoded, &decoded)) + if (!ToASCII(decoded, &decoded)) goto end; // 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; // If the unicode flag is set, run the result through punycode ToUnicode - if (unicode && !ToUnicode(&decoded, &decoded)) + if (unicode && !ToUnicode(decoded, &decoded)) goto end; // 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) && context_.host.length() > 0) { std::string unicode_host; - if (!ToUnicode(&context_.host, &unicode_host)) { + if (!ToUnicode(context_.host, &unicode_host)) { return ""; } return "\\\\" + unicode_host + decoded_path;