aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbpkg/manifest.cxx39
-rw-r--r--libbpkg/manifest.hxx19
-rw-r--r--tests/manifest/testscript49
3 files changed, 99 insertions, 8 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index 139b7a8..55fe18f 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -598,6 +598,21 @@ namespace bpkg
return *this;
}
+ // url
+ //
+ url::
+ url (const std::string& u, std::string c): butl::url (u), comment (move (c))
+ {
+ if (rootless)
+ throw invalid_argument ("rootless URL");
+
+ if (casecmp (scheme, "file") == 0)
+ throw invalid_argument ("local URL");
+
+ if (!authority || authority->empty ())
+ throw invalid_argument ("no authority");
+ }
+
// depends
//
dependency_constraint::
@@ -1631,7 +1646,18 @@ namespace bpkg
if (v.empty ())
bad_value (string ("empty ") + what + " url");
- return url (move (p.first), move (p.second));
+ url r;
+
+ try
+ {
+ r = url (p.first, move (p.second));
+ }
+ catch (const invalid_argument& e)
+ {
+ bad_value (string ("invalid ") + what + " url: " + e.what ());
+ }
+
+ return r;
};
auto flag = [fl] (package_manifest_flags f)
@@ -2514,19 +2540,22 @@ namespace bpkg
}
if (m.url)
- s.next ("url", serializer::merge_comment (*m.url, m.url->comment));
+ s.next ("url",
+ serializer::merge_comment (m.url->string (), m.url->comment));
if (m.doc_url)
s.next ("doc-url",
- serializer::merge_comment (*m.doc_url, m.doc_url->comment));
+ serializer::merge_comment (m.doc_url->string (),
+ m.doc_url->comment));
if (m.src_url)
s.next ("src-url",
- serializer::merge_comment (*m.src_url, m.src_url->comment));
+ serializer::merge_comment (m.src_url->string (),
+ m.src_url->comment));
if (m.package_url)
s.next ("package-url",
- serializer::merge_comment (*m.package_url,
+ serializer::merge_comment (m.package_url->string (),
m.package_url->comment));
if (m.email)
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index 59c0ba0..01ffa49 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -250,16 +250,29 @@ namespace bpkg
};
// url
+ // doc-url
+ // src-url
// package-url
//
- class url: public std::string
+ // URL that has the following constraints:
+ //
+ // - is not rootless
+ // - is not local (the scheme is not `file`)
+ // - authority is present and is not empty
+ //
+ // See libbutl/url.mxx for details.
+ //
+ class url: public butl::url
{
public:
std::string comment;
+ // Throw invalid_argument on parsing or constraints checking error.
+ //
explicit
- url (std::string u = "", std::string c = "")
- : std::string (std::move (u)), comment (std::move (c)) {}
+ url (const std::string& u, std::string c = "");
+
+ url () = default;
};
// email
diff --git a/tests/manifest/testscript b/tests/manifest/testscript
index 96f8f31..e7a6af6 100644
--- a/tests/manifest/testscript
+++ b/tests/manifest/testscript
@@ -138,6 +138,55 @@
stdin:6:19: error: invalid package description file: invalid filesystem path
%)
EOE
+
+ : url
+ :
+ {
+ : no-scheme
+ :
+ $* <<EOI 2>>EOE != 0
+ : 1
+ src-url: libfoo
+ EOI
+ stdin:2:10: error: invalid src url: no scheme
+ EOE
+
+ : rootless
+ :
+ $* <<EOI 2>>EOE != 0
+ : 1
+ src-url: pkcs11:libfoo
+ EOI
+ stdin:2:10: error: invalid src url: rootless URL
+ EOE
+
+ : local
+ :
+ $* <<EOI 2>>EOE != 0
+ : 1
+ src-url: file:/libfoo/bar
+ EOI
+ stdin:2:10: error: invalid src url: local URL
+ EOE
+
+ : authority-absent
+ :
+ $* <<EOI 2>>EOE != 0
+ : 1
+ src-url: http:/libfoo/bar
+ EOI
+ stdin:2:10: error: invalid src url: no authority
+ EOE
+
+ : authority-empty
+ :
+ $* <<EOI 2>>EOE != 0
+ : 1
+ src-url: http:///libfoo/bar
+ EOI
+ stdin:2:10: error: invalid src url: no authority
+ EOE
+ }
}
: complete