Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ jobs:
AGENT = re.compile(r"\b(ChatGPT|Codex|Cursor|Claude)\b", re.I)


def git(*arguments):
return subprocess.check_output(["git", *arguments], text=True, stdin=subprocess.DEVNULL)
def git(*arguments, errors="strict"):
return subprocess.check_output(["git", *arguments], encoding="utf-8", errors=errors,
stdin=subprocess.DEVNULL)


def api_commit(repository, sha):
Expand Down Expand Up @@ -135,8 +136,10 @@ jobs:
paths = git("diff", "--name-only", "--no-renames", "-z", comparison, head).split("\0")
for path in filter(None, paths):
findings.extend(content_findings(path, 1, path, allow_terms))
# Git can emit byte fixtures as text when they contain no NUL. Keep
# scanning their readable content without requiring valid UTF-8.
patch = git("diff", "--no-ext-diff", "--no-color", "--no-renames", "--unified=0",
comparison, head, "--", path)
comparison, head, "--", path, errors="replace")
for number, line in added_lines(patch):
findings.extend(content_findings(path, number, line, allow_terms))
return findings
Expand Down
9 changes: 6 additions & 3 deletions Scripts/check-policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
AGENT = re.compile(r"\b(ChatGPT|Codex|Cursor|Claude)\b", re.I)


def git(*arguments):
return subprocess.check_output(["git", *arguments], text=True, stdin=subprocess.DEVNULL)
def git(*arguments, errors="strict"):
return subprocess.check_output(["git", *arguments], encoding="utf-8", errors=errors,
stdin=subprocess.DEVNULL)


def api_commit(repository, sha):
Expand Down Expand Up @@ -101,8 +102,10 @@ def check_range(repository, base, head, allow_terms, allow_bots, fetch_commit=ap
paths = git("diff", "--name-only", "--no-renames", "-z", comparison, head).split("\0")
for path in filter(None, paths):
findings.extend(content_findings(path, 1, path, allow_terms))
# Git can emit byte fixtures as text when they contain no NUL. Keep
# scanning their readable content without requiring valid UTF-8.
patch = git("diff", "--no-ext-diff", "--no-color", "--no-renames", "--unified=0",
comparison, head, "--", path)
comparison, head, "--", path, errors="replace")
for number, line in added_lines(patch):
findings.extend(content_findings(path, number, line, allow_terms))
return findings
Expand Down
7 changes: 6 additions & 1 deletion Tests/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_real_git_range_and_new_branch(self):
try:
subprocess.run(["git", "init", "-q"], check=True)
def commit(text):
Path("sample.txt").write_text(text)
Path("sample.txt").write_bytes(text if isinstance(text, bytes) else text.encode())
policy.git("add", "sample.txt")
policy.git("-c", "user.name=Fixture", "-c", "[email protected]",
"-c", "commit.gpgsign=false", "-c", "core.hooksPath=/dev/null", "commit", "-qm", "fix: fixture")
Expand All @@ -70,6 +70,11 @@ def commit(text):
head = commit("clean\n/" + "home/fixture/private\n")
findings = policy.check_range("example/repo", base, head, set(), set(), lambda *_: record())
self.assertEqual(findings, ["sample.txt:2: private execution path"])
byte_fixture = commit(b"invalid UTF-8: \xfa\n")
self.assertEqual(policy.check_range("example/repo", head, byte_fixture, set(), set(), lambda *_: record()), [])
unsafe_fixture = commit(b"invalid UTF-8: \xfa\n/" + b"home/fixture/private\n")
self.assertEqual(policy.check_range("example/repo", byte_fixture, unsafe_fixture, set(), set(), lambda *_: record()),
["sample.txt:2: private execution path"])
finally:
os.chdir(previous)

Expand Down