Просмотр исходного кода

fix: re-allow empty strings in ipv6-style URI/IRI

Sam Jaffe 2 недель назад
Родитель
Сommit
ef9be256fe
1 измененных файлов с 5 добавлено и 2 удалено
  1. 5 2
      include/jvalidate/format.h

+ 5 - 2
include/jvalidate/format.h

@@ -196,7 +196,8 @@ template <typename CharT> bool is_uri_authority(std::basic_string_view<CharT> ur
 
   // A URI Authority HOST section
   // If the URI starts with '[', then it MUST BE an IPv6 or an "IPvFuture"
-  if (uri[0] == '[') {
+  bool const has_ipv6 = (uri[0] == '[');
+  if (has_ipv6) {
     size_t pos = uri.find(']');
     auto ip = uri.substr(1, pos - 1);
     uri.remove_prefix(pos + 1);
@@ -214,7 +215,9 @@ template <typename CharT> bool is_uri_authority(std::basic_string_view<CharT> ur
   }
 
   // Normal URI Authority HOST section is either an IPv4 or a HOSTNAME
-  return ipv4(to_u8(uri)) || hostname(uri);
+  // if we had an ipv6 part, we can permit an empty string (since hostname
+  // no longer permits them).
+  return (has_ipv6 && uri.empty()) || ipv4(to_u8(uri)) || hostname(uri);
 }
 
 // Tests if a URI "Query Part" or "Fragment Part" is valid and remove the part