{"record":{"id":"dfef5ed84cfda522","repo":"gohugoio/hugo","slug":"failed-to-match-regex-pattern-against-string-w","errorCode":null,"errorMessage":"failed to match regex pattern against string: %w","messagePattern":"failed to match regex pattern against string: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/strings.go","lineNumber":88,"sourceCode":"// RuneCount returns the number of runes in s.\nfunc (ns *Namespace) RuneCount(s any) (int, error) {\n\tss, err := cast.ToStringE(s)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to convert content to string: %w\", err)\n\t}\n\treturn utf8.RuneCountInString(ss), nil\n}\n\n// CountWords returns the approximate word count in s.\nfunc (ns *Namespace) CountWords(s any) (int, error) {\n\tss, err := cast.ToStringE(s)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to convert content to string: %w\", err)\n\t}\n\n\tisCJKLanguage, err := regexp.MatchString(`\\p{Han}|\\p{Hangul}|\\p{Hiragana}|\\p{Katakana}`, ss)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to match regex pattern against string: %w\", err)\n\t}\n\n\tif !isCJKLanguage {\n\t\treturn len(strings.Fields(tpl.StripHTML(ss))), nil\n\t}\n\n\tcounter := 0\n\tfor word := range strings.FieldsSeq(tpl.StripHTML(ss)) {\n\t\truneCount := utf8.RuneCountInString(word)\n\t\tif len(word) == runeCount {\n\t\t\tcounter++\n\t\t} else {\n\t\t\tcounter += runeCount\n\t\t}\n\t}\n\n\treturn counter, nil\n}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/strings/strings.go#L70-L106","documentation":"Thrown by strings.CountWords when regexp.MatchString fails against the static CJK detection pattern '\\p{Han}|\\p{Hangul}|\\p{Hiragana}|\\p{Katakana}'. Because the pattern is a compile-time constant valid regex, this error is effectively unreachable under normal Go regexp behavior; it would only fire on a regexp engine failure.","triggerScenarios":"Theoretically triggered if the Go regexp engine returns an error matching the static CJK pattern against the input string. In practice this should never occur with a stock Hugo build.","commonSituations":"Essentially never in production. Could appear with a corrupted Go runtime or a non-standard regexp fork. If seen, suspect a runtime/build anomaly rather than user data.","solutions":["Re-run the build; if it persists, this indicates a Go runtime/regexp issue, not user input.","Check that the Hugo binary is built against a standard Go toolchain.","Report as a bug if reproducible since the pattern is hardcoded and valid.","Simplify the input string to isolate whether specific bytes trigger the engine failure."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["This error is effectively unreachable since the regex is a hardcoded valid constant.","If seen, treat as a runtime/build anomaly and rebuild with a standard Go toolchain.","Do not add input-side guards; the trigger is not user data."],"tags":["strings","countwords","regexp","unreachable"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}