Skip to content

Commit 583a436

Browse files
ctruedenclaude
andcommitted
check-accessibility.sh: fix cache bugs
1. Unescaped regex in grep — the url_path was used directly as a grep pattern (grep "^$url_path "). The 4 tutorial pages named [1.01] Fundamentals..., [1.02] Introduction..., etc. have [ and ] in their paths. Grep treats [1.01] as a character class matching 1, ., or 0, so the pattern never matches the literal [. This caused: - cache_hit to always return miss for those 4 pages - cache_update's grep -v to never remove the old entry → duplicate entries accumulated (hence 1666 entries for 1616 files) 2. cut -d' ' -f2 fails for paths with spaces — those same tutorial pages have spaces in their names. When reading back the hash, cut -d' ' -f2 returned Fundamentals instead of the hash. Fix: replaced grep + cut with awk using index($0, p) (literal prefix match) and $NF (last field = hash). Also cleaned up the duplicate entries in the cache. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0e2415e commit 583a436

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

_bin/check-accessibility.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ cache_hit() {
5454
[ -f "$CACHE_FILE" ] || return 1
5555
[ -f "$html_file" ] || return 1
5656
current_hash=$(hash_file "$html_file")
57-
stored=$(grep "^$url_path " "$CACHE_FILE" 2>/dev/null | cut -d' ' -f2)
57+
stored=$(awk -v p="$url_path " 'index($0,p)==1{print $NF;exit}' "$CACHE_FILE" 2>/dev/null)
5858
[ "$stored" = "$current_hash" ]
5959
}
6060

@@ -65,7 +65,7 @@ cache_update() {
6565
[ -f "$html_file" ] || return
6666
current_hash=$(hash_file "$html_file")
6767
tmpfile=$(mktemp)
68-
grep -v "^$url_path " "$CACHE_FILE" 2>/dev/null > "$tmpfile" || true
68+
awk -v p="$url_path " 'index($0,p)!=1' "$CACHE_FILE" 2>/dev/null > "$tmpfile" || true
6969
echo "$url_path $current_hash" >> "$tmpfile"
7070
mv "$tmpfile" "$CACHE_FILE"
7171
}

0 commit comments

Comments
 (0)