mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
fix: Ensure that during migration we make the urls have a trailing slash (#2036)
This is to fix a bug in the UI
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use emver::VersionRange;
|
use emver::VersionRange;
|
||||||
|
use regex::Regex;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
use super::v0_3_0::V0_3_0_COMPAT;
|
use super::v0_3_0::V0_3_0_COMPAT;
|
||||||
@@ -47,7 +48,7 @@ impl VersionT for Version {
|
|||||||
if let Value::Object(known_hosts) = known_hosts {
|
if let Value::Object(known_hosts) = known_hosts {
|
||||||
for (_id, value) in known_hosts {
|
for (_id, value) in known_hosts {
|
||||||
if let Value::String(url) = &value["url"] {
|
if let Value::String(url) = &value["url"] {
|
||||||
ui["marketplace"]["known-hosts"][url] = json!({});
|
ui["marketplace"]["known-hosts"][ensure_trailing_slashes(url)] = json!({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum MarketPlaceUrls {
|
pub enum MarketPlaceUrls {
|
||||||
Default,
|
Default,
|
||||||
|
|||||||
Reference in New Issue
Block a user