diff --git a/launcher/src/browser/horizon.rs b/launcher/src/browser/horizon.rs
index 501295c6b..e56f31e09 100644
--- a/launcher/src/browser/horizon.rs
+++ b/launcher/src/browser/horizon.rs
@@ -190,6 +190,18 @@ fn version_of(index: &Index, p: &index::Project, v: &index::Version) -> Version
}
}
+/// A GitHub login as GitHub allows it (letters, digits, single dashes, at most 39), so an index
+/// entry can't turn a link into something else.
+fn github_login(login: &str) -> bool {
+ (1..=39).contains(&login.len())
+ && login
+ .bytes()
+ .all(|b| b.is_ascii_alphanumeric() || b == b'-')
+ && !login.starts_with('-')
+ && !login.ends_with('-')
+ && !login.contains("--")
+}
+
/// The words of a query found in a project's id, name, summary or authors.
fn matches(p: &index::Project, text: &str) -> bool {
let hay = format!("{} {} {} {}", p.id, p.name, p.summary, p.authors.join(" ")).to_lowercase();
@@ -277,9 +289,14 @@ impl Source for Registry {
body.push_str(&format!("- {} {}{may}\n", m.name, w.version));
}
}
+ // Who publishes it: the GitHub accounts the registry checked at submission.
+ let owners = p.owners.iter().filter(|o| github_login(o)).map(|o| Link {
+ label: format!("@{o}"),
+ url: format!("https://github.com/{o}"),
+ });
Ok(Details {
body,
- links: vec![
+ links: [
Link {
label: "Source".into(),
url: p.source.clone(),
@@ -292,7 +309,10 @@ impl Source for Registry {
label: "Report".into(),
url: format!("{REPORT}&title={}", p.id),
},
- ],
+ ]
+ .into_iter()
+ .chain(owners)
+ .collect(),
authors: p.authors.clone(),
published: p
.versions
diff --git a/launcher/src/browser/horizon/tests.rs b/launcher/src/browser/horizon/tests.rs
index bf98719d7..fb99462e1 100644
--- a/launcher/src/browser/horizon/tests.rs
+++ b/launcher/src/browser/horizon/tests.rs
@@ -143,3 +143,22 @@ fn registry_versions_run_when_made_for_this_game() {
.collect();
assert_eq!(pick(Kind::Mod, &versions, false).unwrap().number, "0.1.0");
}
+
+#[test]
+fn owner_links_only_take_github_logins() {
+ for ok in ["Stink-O", "ludovic111", "a"] {
+ assert!(github_login(ok), "{ok}");
+ }
+ for bad in [
+ "",
+ "-x",
+ "x-",
+ "a--b",
+ "bad login",
+ "a/b",
+ "x?y=1",
+ &"a".repeat(40),
+ ] {
+ assert!(!github_login(bad), "{bad}");
+ }
+}
diff --git a/website/src/mods.js b/website/src/mods.js
index 4819af374..acaee41f0 100644
--- a/website/src/mods.js
+++ b/website/src/mods.js
@@ -79,6 +79,19 @@ function installHtml(p, v) {
`;
}
+// GitHub's rule for a login: letters, digits and single dashes, at most 39.
+const LOGIN = /^(?!-)(?!.*--)[A-Za-z0-9-]{1,39}(? LOGIN.test(o));
+ if (!owners.length) return "";
+ const links = owners
+ .map((o) => `
@${o}`)
+ .join(" ");
+ return `
Published by ${links}
`;
+}
+
// One project's page.
export function projectHtml(p) {
const v = p.versions[0];
@@ -93,7 +106,7 @@ export function projectHtml(p) {
.map((x) => `${escape(x.version)} ${escape(x.published || "")} · for ${escape(x.game)}${x.api ? ` · API ${escape(x.api)}` : ""}${x.changelog ? `${markdown(x.changelog)}
` : ""}`)
.join("");
return `
- ${icon(p)}${escape(KIND_NAMES[p.kind] || p.kind)}${escape((p.authors || []).join(", "))}
+
${p.description ? `
${markdown(p.description)}
` : ""}
diff --git a/website/src/mods.test.mjs b/website/src/mods.test.mjs
index 75e3ca4c5..c5ff2e783 100644
--- a/website/src/mods.test.mjs
+++ b/website/src/mods.test.mjs
@@ -53,3 +53,11 @@ test("the submit form sends what the service reads", () => {
assert.equal(entry.icon, undefined);
assert.equal(JSON.parse(JSON.stringify(entry)).key, undefined, "an empty key isn't sent");
});
+
+test("a project's page links its owners' GitHub profiles, and only valid logins", () => {
+ const html = projectHtml(project({ owners: ["Stink-O", "bad login", "-x", "a--b", "ok\">