Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure that during migration we make the urls have a trailing slash #2036

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion backend/src/version/v0_3_3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_trait::async_trait;
use emver::VersionRange;
use regex::Regex;
use serde_json::{json, Value};

use super::v0_3_0::V0_3_0_COMPAT;
Expand Down Expand Up @@ -47,7 +48,7 @@ impl VersionT for Version {
if let Value::Object(known_hosts) = known_hosts {
for (_id, value) in known_hosts {
if let Value::String(url) = &value["url"] {
ui["marketplace"]["known-hosts"][url] = json!({});
ui["marketplace"]["known-hosts"][ensure_trailing_slashes(url)] = json!({});
}
}
}
Expand Down Expand Up @@ -101,6 +102,32 @@ impl VersionT for Version {
}
}

fn ensure_trailing_slashes(url: &str) -> String {
lazy_static::lazy_static! {
static ref REG: Regex = Regex::new(r".*/$").unwrap();
}
if REG.is_match(url) {
return url.to_string();
}
format!("{url}/")
}

#[test]
fn test_ensure_trailing_slashed() {
assert_eq!(
&ensure_trailing_slashes("http://start9.com"),
"http://start9.com/"
);
assert_eq!(
&ensure_trailing_slashes("http://start9.com/"),
"http://start9.com/"
);
assert_eq!(
&ensure_trailing_slashes("http://start9.com/a"),
"http://start9.com/a/"
);
}

#[derive(Debug, Clone, Copy)]
pub enum MarketPlaceUrls {
Default,
Expand Down