mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 09:46:29 +01:00
fix(update): preserve exact matching for non-GitHub download prefixes
This commit is contained in:
1 parent
3d1cac4141
commit
c2ec2415e8
1 file changed
+11
-2
@@ -146,6 +146,7 @@ pub fn expected_download_url(repo: &str, tag: &str, name: &str) -> Option<String
|
||||
/// `+`. GitHub serves a `+` in a download path the same either way, and links built before
|
||||
/// `%2B` (an older launcher's feed, or a release saved by an older version) write it plainly.
|
||||
/// No other escape is read, so `%2b` or `%2e` still has to match as written.
|
||||
/// For GitHub links, the owner and repository names compare case-insensitively.
|
||||
pub fn same_download_url(url: &str, expected: &str) -> bool {
|
||||
let (url, expected) = github_repository_paths(url, expected).unwrap_or((url, expected));
|
||||
url == expected || url.replace("%2B", "+") == expected.replace("%2B", "+")
|
||||
@@ -169,8 +170,8 @@ fn github_repository_paths<'a>(url: &'a str, expected: &'a str) -> Option<(&'a s
|
||||
/// segments with no traversal (`.`/`..`), no additional slashes, no query or fragment, and no
|
||||
/// backslash or percent-encoded separators that a client could later re-interpret.
|
||||
pub fn download_url_under(url: &str, prefix: &str) -> bool {
|
||||
let Some((path, prefix)) = github_repository_paths(url, prefix) else { return false };
|
||||
let Some(rest) = path.strip_prefix(prefix) else { return false };
|
||||
let (url, prefix) = github_repository_paths(url, prefix).unwrap_or((url, prefix));
|
||||
let Some(rest) = url.strip_prefix(prefix) else { return false };
|
||||
download_suffix_ok(rest)
|
||||
}
|
||||
|
||||
@@ -387,6 +388,14 @@ pub(crate) mod tests {
|
||||
|
||||
const REPO: &str = "storytold/photocraft";
|
||||
|
||||
#[trial]
|
||||
fn download_url_under_preserves_exact_non_github_prefixes() {
|
||||
let prefix = "https://example.com/Releases/";
|
||||
assert!(download_url_under("https://example.com/Releases/v1/file.zip", prefix));
|
||||
assert!(!download_url_under("https://example.com/releases/v1/file.zip", prefix));
|
||||
assert!(!download_url_under("https://example.com/Releases/v1/file.zip?query=1", prefix));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn github_download_matching_ignores_only_repository_case() {
|
||||
let repo = "Storytold/PdfCraft";
|
||||
|
||||
Reference in new issue
Block a user