Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(skills): percent-encode repo paths in skills.sh download URLs

M3gA-Mindebc61bdd6ab7
diff --git a/crates/openhuman-core/src/skills/catalog/download.rs b/crates/openhuman-core/src/skills/catalog/download.rs
index d19f4d6434..aa97e38df2 100644
--- a/crates/openhuman-core/src/skills/catalog/download.rs
+++ b/crates/openhuman-core/src/skills/catalog/download.rs
@@ -65,8 +65,16 @@ impl<'a> SkillsShRef<'a> {
.collect()
}
+ /// Raw URL of `path` in this repo. Each segment is percent-encoded: a path
+ /// from the repo's tree listing can hold `#`, `?` or spaces, which would
+ /// otherwise cut the URL short or change what it names.
fn raw_url(&self, path: &str) -> String {
- format!("{GITHUB_RAW}/{}/{}/HEAD/{path}", self.owner, self.repo)
+ let mut url = url::Url::parse(GITHUB_RAW).expect("GITHUB_RAW is a valid base URL");
+ url.path_segments_mut()
+ .expect("an https URL has path segments")
+ .extend([self.owner, self.repo, "HEAD"])
+ .extend(path.split('/'));
+ url.into()
}
/// Locate this skill's `SKILL.md` in its GitHub repo.
diff --git a/crates/openhuman-core/src/skills/catalog/download_tests.rs b/crates/openhuman-core/src/skills/catalog/download_tests.rs
index fa78e513ee..31e1a327c5 100644
--- a/crates/openhuman-core/src/skills/catalog/download_tests.rs
+++ b/crates/openhuman-core/src/skills/catalog/download_tests.rs
@@ -67,6 +67,15 @@ fn find_skill_md_in_tree_matches_the_skill_directory_at_any_depth() {
);
}
+#[test]
+fn raw_url_percent_encodes_segments_from_a_tree_listing() {
+ let skill = SkillsShRef::parse("https://skills.sh/o/r/my-skill").unwrap();
+ assert_eq!(
+ skill.raw_url("docs #1/what?/my-skill/SKILL.md"),
+ "https://raw.githubusercontent.com/o/r/HEAD/docs%20%231/what%3F/my-skill/SKILL.md"
+ );
+}
+
#[test]
fn find_skill_md_in_tree_refuses_to_guess_between_same_named_directories() {
let tree = json!({ "tree": [