aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbutl/url.mxx11
-rw-r--r--libbutl/url.txx9
-rw-r--r--tests/url/driver.cxx12
3 files changed, 15 insertions, 17 deletions
diff --git a/libbutl/url.mxx b/libbutl/url.mxx
index a81162c..c696eaa 100644
--- a/libbutl/url.mxx
+++ b/libbutl/url.mxx
@@ -254,12 +254,11 @@ LIBBUTL_MODEXPORT namespace butl
//
basic_url () = default;
- // Create the URL object from its string representation. If the argument is
- // empty, then create an empty object. Otherwise verify that the string is
- // compliant to the generic URL syntax. URL-decode and validate components
- // with common for all schemes syntax (scheme, host, port, path).
- // Throw std::invalid_argument if the passed string is not a valid URL
- // representation.
+ // Create the URL object from its string representation. Verify that the
+ // string is compliant to the generic URL syntax. URL-decode and validate
+ // components with common for all schemes syntax (scheme, host, port,
+ // path). Throw std::invalid_argument if the passed string is not a valid
+ // URL representation.
//
// Validation and URL-decoding of the scheme-specific components can be
// provided by a custom url_traits::translate_scheme() implementation.
diff --git a/libbutl/url.txx b/libbutl/url.txx
index 26bd60a..b520509 100644
--- a/libbutl/url.txx
+++ b/libbutl/url.txx
@@ -226,14 +226,11 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
using iterator = typename string_type::const_iterator;
- // Create an empty URL object for the empty argument. Note that the scheme
- // is default-constructed, and so may stay undefined in this case.
- //
- if (u.empty ())
- return;
-
try
{
+ if (u.empty ())
+ throw invalid_argument ("empty URL");
+
// At the end of a component parsing 'i' points to the next component
// start, and 'b' stays unchanged.
//
diff --git a/tests/url/driver.cxx b/tests/url/driver.cxx
index 5fbeaa2..64bc2b5 100644
--- a/tests/url/driver.cxx
+++ b/tests/url/driver.cxx
@@ -169,9 +169,8 @@ try
// Test ctors and operators.
//
{
- wurl u0 ((wstring ()));
+ wurl u0;
assert (u0.empty ());
- assert (u0 == wurl ());
wurl u1 (scheme::http,
wurl_authority {wstring (), wurl_host (L"[123]"), 0},
@@ -288,7 +287,7 @@ try
{
case print_mode::str:
{
- cout << url (ua) << endl;
+ cout << (*ua != '\0' ? url (ua) : url ()) << endl;
break;
}
case print_mode::wstr:
@@ -297,7 +296,7 @@ try
//
wstring s (ua, ua + strlen (ua));
- wcout << wurl (s) << endl;
+ wcout << (!s.empty () ? wurl (s) : wurl ()) << endl;
break;
}
case print_mode::comp:
@@ -305,7 +304,10 @@ try
// Convert ASCII string to wstring.
//
wstring s (ua, ua + strlen (ua));
- wurl u (s);
+
+ wurl u;
+ if (!s.empty ())
+ u = wurl (s);
if (!u.empty ())
{