fix: catalog reads project files through Base64, shared PowerShell helper
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
cfd9ffe943
commit
df4605bac1
4 files changed
+121
-57
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { decode } from "../herdr/herdr-composer/mods/herdr-composer/powershell.js";
|
||||
import { readScript } from "../herdr/herdr-composer/mods/herdr-composer/catalog.js";
|
||||
|
||||
const NASTY = [
|
||||
".claude/commands/it\u2019s.md",
|
||||
".claude/commands/it\u2018s.md",
|
||||
".claude/commands/a\u201Ab\u201Bc.md",
|
||||
".claude/commands/o'brien.md",
|
||||
".claude/commands/$env:USERNAME.md",
|
||||
'.claude/commands/"; calc #.md',
|
||||
".claude/skills/zażółć gęślą/SKILL.md",
|
||||
];
|
||||
|
||||
const b64s = (script) =>
|
||||
[...script.matchAll(/FromBase64String\('([A-Za-z0-9+/=]*)'\)/g)].map((m) => Buffer.from(m[1], "base64").toString("utf8"));
|
||||
|
||||
test("decode: PowerShell that yields the text, with the text itself nowhere in it", () => {
|
||||
for (const text of NASTY) {
|
||||
const expr = decode(text);
|
||||
assert.deepEqual(b64s(expr), [text]);
|
||||
assert.equal(expr.includes(text), false);
|
||||
assert.match(expr, /^\[System\.Text\.Encoding\]::UTF8\.GetString\(\[System\.Convert\]::FromBase64String\('[A-Za-z0-9+/=]*'\)\)$/);
|
||||
}
|
||||
});
|
||||
|
||||
test("decode: every length of tail, emoji, newline, empty", () => {
|
||||
for (const text of ["", "a", "ab", "abc", "abcd", "ęą", "😀x", "a\nb"]) {
|
||||
assert.deepEqual(b64s(decode(text)), [text]);
|
||||
}
|
||||
});
|
||||
|
||||
test("catalog readScript: the path of a project file is only ever Base64", () => {
|
||||
for (const path of NASTY) {
|
||||
const script = readScript(path);
|
||||
assert.deepEqual(b64s(script), [path]);
|
||||
for (const raw of ["\u2019", "\u2018", "\u201A", "\u201B", "$env:USERNAME", "calc", "o'brien", "zażółć"]) {
|
||||
if (path.includes(raw)) assert.equal(script.includes(raw), false, `${raw} in the script`);
|
||||
}
|
||||
// the script still reads the file
|
||||
assert.ok(script.includes("Get-Content"));
|
||||
assert.ok(script.includes("-LiteralPath"));
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user