Plug-in Library: release and repo URLs with white space are refused

Install and Preview, the catalog schema and scripts/validate.sh now refuse a release URL or repo folder that contains white space in any segment, the tag and file name included: any Unicode white space character, and U+FEFF. Before, the app accepted a space or tab in a tag, file name or repo folder that the schema refused.
This commit is contained in:
dotCooCoo committed 2026-11-06 00:49:16 -08:00
1 parent cc90ad0c3b
commit 36dc209bad
3 files changed
+25 -7

No files matched your search

+17 -2
View File
@@ -272,12 +272,18 @@ fn dot_segment(p: &str) -> bool {
p == "." || p == ".."
}
/// A character a release or repository URL may not contain: `?`, `#`, `\`, Unicode white space,
/// or U+FEFF (the catalog schema's `\s` matches it too).
fn bad_url_char(c: char) -> bool {
matches!(c, '?' | '#' | '\\' | '\u{feff}') || c.is_whitespace()
}
/// `(owner, name)` in lower case of a `https://github.com/<owner>/<name>` repository URL (an
/// optional trailing `/` or `.git`) or of a folder in one, `https://github.com/<owner>/<name>/tree/<ref>/<path>`;
/// `None` for anything else.
fn github_repo(repo: &str) -> Option<(String, String)> {
let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?;
if rest.contains(['?', '#', '\\']) {
if rest.contains(bad_url_char) {
return None;
}
let rest = rest.strip_suffix('/').unwrap_or(rest);
@@ -296,7 +302,7 @@ fn github_repo(repo: &str) -> Option<(String, String)> {
fn release_url_problem(repo: &str, url: &str) -> Option<String> {
let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com/<owner>/<repo>/releases/download/<tag>/<file>)"));
let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() };
if rest.contains(['?', '#', '\\']) {
if rest.contains(bad_url_char) {
return not_asset();
}
let parts: Vec<&str> = rest.split('/').collect();
@@ -1230,6 +1236,12 @@ mod tests {
"https://github.com/me/glow/releases/download/./v1/x.wasm",
"https://github.com/me/glow/releases/download/v1\\x.wasm",
"https://github.com/m e/glow/releases/download/v1/x.wasm",
"https://github.com/me/glow/releases/download/v 1/x.wasm",
"https://github.com/me/glow/releases/download/v1/x\t.wasm",
"https://github.com/me/glow/releases/download/v1/x.wasm\n",
"https://github.com/me/glow/releases/download/v1\u{a0}/x.wasm",
"https://github.com/me/glow/releases/download/v1/\u{85}x.wasm",
"https://github.com/me/glow/releases/download/v1/x\u{feff}.wasm",
"https://github.com/../glow/releases/download/v1/x.wasm",
"https://github.com.evil.com/me/glow/releases/download/v1/x.wasm",
] {
@@ -1281,6 +1293,9 @@ mod tests {
"https://github.com/me/glow?tab=readme",
"https://github.com/me/glow#readme",
"https://github.com/me/gl ow",
"https://github.com/me/glow/tree/main/my plug-in",
"https://github.com/me/glow/tree/ma\tin",
"https://github.com/me/glow/tree/main/x\u{feff}",
"https://github.com/me/..",
] {
let why = release_url_problem(repo, asset);
+2 -2
View File
@@ -14,7 +14,7 @@
"version": {"type": "string", "maxLength": 32, "pattern": "^[0-9]+(\\.[0-9]+)*$"},
"release_url": {
"type": "string",
"pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s]+(/[^/?#\\\\\\s]+)+$"
"pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s\\u0085]+(/[^/?#\\\\\\s\\u0085]+)+$"
},
"package": {
"type": "object",
@@ -26,7 +26,7 @@
"author": {"type": "string"},
"description": {"type": "string"},
"license": {"type": "string"},
"repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s]+)+)?/?$"},
"repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s\\u0085]+)+)?/?$"},
"tags": {"type": "array", "items": {"type": "string"}},
"preview": {
"type": "object",
+6 -3
View File
@@ -49,25 +49,28 @@ echo "== 3. release URLs"
bad=$(jq -r '
# A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded).
def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == "..");
# A `?`, `#`, `\` or white space character (Unicode, and U+FEFF), which EffectCraft refuses in a URL.
def bad_char: test("[?#\\\\\t\n\u000b\f\r \u0085   - 

   ]");
# "owner/name" in lower case of a release asset,
# https://github.com/<owner>/<name>/releases/download/<tag>/<file> (a tag may contain `/`), with
# no query, fragment, backslash, or empty, `.` or `..` segment; "?" for anything else.
# no query, fragment, backslash, white space, or empty, `.` or `..` segment; "?" for anything else.
def asset_of:
if startswith("https://") and (.[8:19] | ascii_downcase) == "github.com/" then
.[19:] as $rest
| ($rest | split("/")) as $p
| if ($rest | test("[?#\\\\]")) or ($p | length) < 6 or ($p | any(bad_segment))
| if ($rest | bad_char) or ($p | length) < 6 or ($p | any(bad_segment))
or ($p[0] | test("^[A-Za-z0-9._-]+$") | not) or ($p[1] | test("^[A-Za-z0-9._-]+$") | not)
or $p[2] != "releases" or $p[3] != "download"
then "?" else "\($p[0])/\($p[1])" | ascii_downcase end
else "?" end;
# Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case.
def repo_of:
if bad_char then "?" else
(capture("^(?<h>[^/]+//[^/]+)/(?<o>[A-Za-z0-9._-]+)/(?<n>[A-Za-z0-9._-]+?)(\\.git)?/?$")
// (capture("^(?<h>[^/]+//[^/]+)/(?<o>[A-Za-z0-9._-]+)/(?<n>[A-Za-z0-9._-]+)/tree/(?<f>[^?#\\\\]+?)/?$")
| select(.f | split("/") | any(bad_segment) | not))
| select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not))
| "\(.o)/\(.n)" | ascii_downcase) // "?";
| "\(.o)/\(.n)" | ascii_downcase) // "?" end;
.packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo
| (if $repo == "" then "" else $repo | repo_of end) as $want
| .versions[] | select(.url | startswith("file://") | not)