aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--crates/mozart/Cargo.toml1
-rw-r--r--crates/mozart/src/commands/browse.rs15
-rw-r--r--crates/mozart/src/commands/init.rs12
5 files changed, 19 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1788a06..b692f5b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1092,6 +1092,7 @@ dependencies = [
"tokio",
"tracing",
"tracing-subscriber",
+ "url",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index e17f8ba..4c7949e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -31,6 +31,7 @@ proc-macro2 = "1.0.106"
quote = "1.0.44"
regex = "1.12.3"
reqwest = { version = "0.13.2", features = ["json"] }
+url = "2"
self-replace = "1.5.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
diff --git a/crates/mozart/Cargo.toml b/crates/mozart/Cargo.toml
index 443cd9e..599c2a1 100644
--- a/crates/mozart/Cargo.toml
+++ b/crates/mozart/Cargo.toml
@@ -21,6 +21,7 @@ serde_json.workspace = true
sha1.workspace = true
tempfile.workspace = true
tokio.workspace = true
+url.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
diff --git a/crates/mozart/src/commands/browse.rs b/crates/mozart/src/commands/browse.rs
index 9a663e5..a88e503 100644
--- a/crates/mozart/src/commands/browse.rs
+++ b/crates/mozart/src/commands/browse.rs
@@ -248,7 +248,10 @@ fn extract_url_from_packagist(
// ─── Helpers ──────────────────────────────────────────────────────────────────
fn is_valid_url(url: &str) -> bool {
- url.starts_with("http://") || url.starts_with("https://")
+ match url::Url::parse(url) {
+ Ok(parsed) => matches!(parsed.scheme(), "http" | "https"),
+ Err(_) => false,
+ }
}
fn open_browser(url: &str) -> anyhow::Result<()> {
@@ -261,7 +264,7 @@ fn open_browser(url: &str) -> anyhow::Result<()> {
#[cfg(target_os = "windows")]
{
Command::new("cmd")
- .args(["/C", "start", "", url])
+ .args(["/C", "start", "web", "explorer", url])
.status()?;
return Ok(());
}
@@ -341,12 +344,12 @@ mod tests {
#[test]
fn test_is_valid_url() {
- assert!(is_valid_url("https://github.com/foo/bar"));
- assert!(is_valid_url("http://example.com"));
+ assert!(!is_valid_url("https://"));
+ assert!(is_valid_url("https://example.com"));
+ assert!(is_valid_url("http://example.com/path?query=1"));
assert!(!is_valid_url("ftp://example.com"));
- assert!(!is_valid_url("git@github.com:foo/bar.git"));
- assert!(!is_valid_url(""));
assert!(!is_valid_url("not-a-url"));
+ assert!(!is_valid_url(""));
}
// ── extract_url_from_locked ───────────────────────────────────────────────
diff --git a/crates/mozart/src/commands/init.rs b/crates/mozart/src/commands/init.rs
index 15729a8..dc32c7c 100644
--- a/crates/mozart/src/commands/init.rs
+++ b/crates/mozart/src/commands/init.rs
@@ -162,11 +162,13 @@ fn build_non_interactive(args: &InitArgs, working_dir: &Path) -> anyhow::Result<
.clone()
.or_else(|| std::env::var("COMPOSER_DEFAULT_LICENSE").ok());
if let Some(ref license) = resolved_license
- && !validation::validate_license(license) && !license.eq_ignore_ascii_case("proprietary") {
- bail!(
- "Invalid license provided: {license}. Only SPDX license identifiers (https://spdx.org/licenses/) or \"proprietary\" are accepted."
- );
- }
+ && !validation::validate_license(license)
+ && !license.eq_ignore_ascii_case("proprietary")
+ {
+ bail!(
+ "Invalid license provided: {license}. Only SPDX license identifiers (https://spdx.org/licenses/) or \"proprietary\" are accepted."
+ );
+ }
composer.license = resolved_license;
if let Some(ref stability) = args.stability {