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
7 changes: 6 additions & 1 deletion hat
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,12 @@ name = re.sub(r"-+", "-", name).strip("-")
if preserve_ext == "true" and orig_ext:
if "." in name:
name = name.rsplit(".", 1)[0]
name = name + "." + orig_ext
name = name.strip("-.")
# An empty stem means the model gave nothing usable (e.g. a reasoning model
# that spent its budget inside <think> and emitted no answer). Emit no name
# so the caller's empty-guard rejects it, instead of renaming the file to a
# stem-less dotfile like ".jpg".
name = name + "." + orig_ext if name else ""
print(name)
SANITIZE
}
Expand Down
20 changes: 20 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ teardown_file() {
assert_output "second-name.txt"
}

# Regression: a degenerate model answer (empty / think-only / punctuation) must
# NOT become a stem-less dotfile like ".jpg" — that slips past the caller's
# empty-name guard and renames the file to a hidden, stem-less file. Emit
# nothing so the rename is rejected.

@test "sanitize: empty answer yields no name (not a dotfile)" {
run sanitize_name "" "true" "jpg"
assert_output ""
}

@test "sanitize: think-only answer yields no name" {
run sanitize_name "<think>spent my whole budget reasoning</think>" "true" "jpg"
assert_output ""
}

@test "sanitize: punctuation-only answer yields no name" {
run sanitize_name "." "true" "jpg"
assert_output ""
}

# ── Binary detection ─────────────────────────────────────────────────

@test "binary: text file is not binary" {
Expand Down
Loading