Skip to content

regexp/syntax: [a-y] parses as [a-z] with (?i) #73456

@rgmz

Description

@rgmz

Go version

go version go1.24.2 linux/amd64

Output of go env in your module/workspace:

`go env` output
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE='on'
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/me/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/me/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3280803028=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/me/dev/github.com/gitleaks/gitleaks/go.mod'
GOMODCACHE='/home/me/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/rich/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/usr/lib/golang'
GOSUMDB='off'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/me/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I was writing test cases to detect "strange" character class ranges (i.e., a user does =-_ and inadvertently creates a range). It appears there is a bug with how syntax.Parse handles character ranges in conjunction with (?i).

https://go.dev/play/p/2p8l3zJi-4T

Note: [a-x] reference in the title refers to any range other than a-z.

What did you see happen?

The pattern (?i)[a-l0-9=-_] is parsed as a-z and not a-l as expected.

Pattern is: [0-9=-_a-zſK]
Pattern is: [0-9=A-L_a-lK]
Pattern is: [0-9=-_a-l]
Pattern is: [0-9=A-L_a-l]

What did you expect to see?

All patterns are printed as [a-l].

Pattern is: [0-9=-_a-lſK]
Pattern is: [0-9=A-L_a-lK]
Pattern is: [0-9=-_a-l]
Pattern is: [0-9=A-L_a-l]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.WorkingAsIntendedIssues describing something that is working as it is supposed to.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions