From 2a3d1494aa31c59e451b4b4017706add8fda20e6 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 18 May 2018 21:12:39 +0300 Subject: [PATCH] Better is_ascii_host_char. GitOrigin-RevId: 25c42be7223691ae9623061ed495b99940b1d79a --- tdutils/td/utils/port/IPAddress.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tdutils/td/utils/port/IPAddress.cpp b/tdutils/td/utils/port/IPAddress.cpp index e8d925a1..3c5f07a0 100644 --- a/tdutils/td/utils/port/IPAddress.cpp +++ b/tdutils/td/utils/port/IPAddress.cpp @@ -29,13 +29,12 @@ namespace td { static bool is_ascii_host_char(char c) { - return is_alnum(c) || c == '-'; + return static_cast(c) <= 127; } static bool is_ascii_host(Slice host) { for (auto c : host) { - // ':' and '@' are not allowed in a host name anyway, so we can skip them - if (!is_ascii_host_char(c) && c != '.' && c != ':' && c != '@') { + if (!is_ascii_host_char(c)) { return false; } } @@ -55,7 +54,7 @@ Result idn_to_ascii(CSlice host) { wchar_t punycode[256]; int result_length = IdnToAscii(IDN_ALLOW_UNASSIGNED, whost.c_str(), whost.size(), punycode, 255); if (result_length == 0) { - return Status::Error("Host can't be punycoded"); + return Status::Error("Host can't be converted to ASCII"); } TRY_RESULT(idn_host, from_wstring(punycode, result_length));