Fix bd-6ku3: Update isHashID to recognize Base36 hash IDs

- Changed pattern from [a-f] (hex) to [a-z] (Base36)
- Added length check: 5+ chars = hash ID (sequential IDs rarely exceed 4 digits)
- Fixes test failure where all-digit Base36 IDs were incorrectly identified as sequential
This commit is contained in:
Steve Yegge
2025-11-06 19:22:12 -08:00
parent 41b1a21206
commit c9247312df
2 changed files with 15 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@@ -326,21 +326,27 @@ func replaceIDReferences(text string, mapping map[string]string) string {
// isHashID checks if an ID is hash-based (not sequential) // isHashID checks if an ID is hash-based (not sequential)
func isHashID(id string) bool { func isHashID(id string) bool {
// Hash IDs contain hex characters after the prefix // Hash IDs are Base36-encoded (0-9, a-z) with adaptive length (3-8 chars)
// Sequential IDs are only digits // Sequential IDs are numeric and typically short (1-4 digits)
parts := strings.SplitN(id, "-", 2) parts := strings.SplitN(id, "-", 2)
if len(parts) != 2 { if len(parts) != 2 {
return false return false
} }
// Check if the suffix starts with a hex digit (a-f)
suffix := parts[1] suffix := parts[1]
if len(suffix) == 0 { if len(suffix) == 0 {
return false return false
} }
// If it contains any letter a-f, it's a hash ID // If it's 5+ characters long, it's almost certainly a hash ID
return regexp.MustCompile(`[a-f]`).MatchString(suffix) // (sequential IDs rarely exceed 9999 = 4 digits)
if len(suffix) >= 5 {
return true
}
// For shorter IDs, check if it contains any letter (a-z)
// Sequential IDs are purely numeric
return regexp.MustCompile(`[a-z]`).MatchString(suffix)
} }
// saveMappingFile saves the ID mapping to a JSON file // saveMappingFile saves the ID mapping to a JSON file