• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-playground / validator / 40376692636
73%
v8: 100%

Build:
Build:
LAST BUILD BRANCH: fix/duration-translations
DEFAULT BRANCH: v8
Ran 26 Oct 2026 06:20PM UTC
Jobs 1
Files 36
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

26 Oct 2026 06:19PM UTC coverage: 72.569%. Remained the same
40376692636

push

github

web-flow
fix: anchor GB and LI postcode patterns as a whole (#1646)

## Fixes Or Enhances

Fixes a false accept in `postcode_iso3166_alpha2` for GB and LI. Both
patterns in
`postcode_regexes.go` contain a top level `|` sitting between `^` and
`$`, and in RE2
those are ordinary assertions that bind only to the branch they appear
in. So
`^a|b$` parses as `(^a)|(b$)`, and the middle alternatives were
effectively
unanchored.

The concrete effect: `postcode_iso3166_alpha2=GB` accepted any string
*ending* in a
valid UK postcode, or in a `BFPO nnnn` token, and
`postcode_iso3166_alpha2=LI`
accepted any string ending in `9490`-`9497`. Plainly non-postcode input
validated as
a postcode:

```go
v := validator.New()
v.Var("junkEC1A 1BB", "postcode_iso3166_alpha2=GB")    // observed nil error, expected non-nil
v.Var("prefixBFPO 1234", "postcode_iso3166_alpha2=GB") // observed nil error, expected non-nil
v.Var("9485junk", "postcode_iso3166_alpha2=LI")        // observed nil error, expected non-nil
```

Why the fix is correct: wrapping each alternation, `^(?:...)$`, makes
the anchors
apply to the whole expression rather than to one branch. That is already
the form
used by 15 of the 16 sibling country patterns with alternations, so this
brings GB
and LI in line with `AR`, `BH`, `EC` and the rest, and matches the
documented intent
of `postcode_iso3166_alpha2=XX` as validating a postcode rather than a
substring of
one.

Tests were added to `TestPostCodeByIso3166Alpha2` covering `junkEC1A
1BB`,
`prefixBFPO 1234`, `EC1A 1BBjunk`, `9485junk` and `x9497`, plus positive
cases
`BFPO 1234`, `9485` and `9497`. I confirmed the new cases fail against
the unpatched
pattern (`--- FAIL: TestPostCodeByIso3166Alpha2 ...
postcode_iso3166_alpha2=LI failed`)
and pass with it.

Full suite, with the race detector, as `make test` runs it:

```
ok  github.com/go-playground/validator/v10  1.116s  coverage: 96.8% of statements
```

`go test ./...` is green across all 25 packages, `go vet ./...` is
cle... (continued)

15013 of 20688 relevant lines covered (72.57%)

89.25 hits per line

Jobs
ID Job ID Ran Files Coverage
1 40376692636.1 26 Oct 2026 06:20PM UTC 36
72.57
GitHub Action Run
Source Files on build 40376692636
  • Tree
  • List 36
  • Changed 0
  • Source Changed 0
  • Coverage Changed 0
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • c9cfe75c on github
  • Prev Build on master (#40376431493)
  • Next Build on master (#40600899027)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc