Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ 1.23.x, 1.24.x, tip ]
go-version: [1.24.x, 1.25.x, tip]
steps:
- name: Set up Go stable
if: matrix.go-version != 'tip'
Expand All @@ -32,17 +32,17 @@ jobs:
- name: test
run: make test
- name: govulncheck
if: matrix.go-version != 'tip'
if: matrix.go-version == '1.25.x'
uses: golang/govulncheck-action@v1
with:
go-version-input: ${{ matrix.go-version }}
check-latest: true
go-package: ./...
- name: golangci-lint
if: matrix.go-version == '1.24.x'
uses: golangci/golangci-lint-action@v8
if: matrix.go-version == '1.25.x'
uses: golangci/golangci-lint-action@v9
with:
version: v2.1.6
version: v2.6.1
- name: integration test
if: matrix.go-version == '1.24.x'
if: matrix.go-version == '1.25.x'
run: tests/system_test.sh
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.0

require (
github.com/JaderDias/movingmedian v0.0.0-20220813210630-d8c6b6de8835
github.com/alecthomas/assert/v2 v2.11.0
github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746
github.com/davecgh/go-spew v1.1.1
github.com/dgryski/go-expirecache v0.0.0-20170314133854-743ef98b2adb
Expand Down Expand Up @@ -32,6 +33,7 @@ require (

require (
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect
github.com/alecthomas/repr v0.4.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 // indirect
Expand All @@ -44,6 +46,7 @@ require (
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ github.com/JaderDias/movingmedian v0.0.0-20220813210630-d8c6b6de8835 h1:mbxQnovj
github.com/JaderDias/movingmedian v0.0.0-20220813210630-d8c6b6de8835/go.mod h1:zsfWLaDctbM7aV1TsQAwkVswuKQ0k7PK4rjC1VZqpbI=
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTNVW4PtpQb8aKA4Pjy0CdJHEqvFbAnvR5m2g=
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -100,6 +104,8 @@ github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
1 change: 0 additions & 1 deletion pkg/expr/functions/cairo/cairo_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build cairo
// +build cairo

package cairo

Expand Down
1 change: 0 additions & 1 deletion pkg/expr/functions/cairo/png/cairo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build cairo
// +build cairo

package png

Expand Down
1 change: 0 additions & 1 deletion pkg/expr/functions/cairo/png/pixel_ratio.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build cairo
// +build cairo

package png

Expand Down
1 change: 0 additions & 1 deletion pkg/expr/functions/cairo/png/png.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !cairo
// +build !cairo

package png

Expand Down
1 change: 0 additions & 1 deletion pkg/expr/types/cairo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build cairo
// +build cairo

package types

Expand Down
2 changes: 1 addition & 1 deletion pkg/expr/types/png.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !cairo
//go:build !cairo

package types

Expand Down
25 changes: 15 additions & 10 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,19 @@ func (e *expr) insertFirstArg(exp *expr) error {
return nil
}

func parseExprWithoutPipe(e string) (Expr, string, error) {
// skip whitespace
for len(e) > 1 && unicode.IsSpace(rune(e[0])) {
e = e[1:]
func skipWhitespace(e string) string {
skipTo := len(e)
for i, r := range e {
if !unicode.IsSpace(r) {
skipTo = i
break
}
}
return e[skipTo:]
}

func parseExprWithoutPipe(e string) (Expr, string, error) {
e = skipWhitespace(e)

if len(e) == 0 {
return nil, "", ErrMissingExpr
Expand Down Expand Up @@ -393,9 +401,7 @@ func ParseExpr(e string) (Expr, string, error) {
}

func pipe(exp *expr, e string) (*expr, string, error) {
for len(e) > 1 && unicode.IsSpace(rune(e[0])) {
e = e[1:]
}
e = skipWhitespace(e)

if e == "" || e[0] != '|' {
return exp, e, nil
Expand Down Expand Up @@ -452,7 +458,7 @@ func parseArgList(e string) (string, []*expr, map[string]*expr, string, error) {
e = e[1:]

// check for empty args
t := strings.TrimLeftFunc(e, unicode.IsSpace)
t := skipWhitespace(e)
if t != "" && t[0] == ')' {
return "", posArgs, namedArgs, t[1:], nil
}
Expand Down Expand Up @@ -519,7 +525,7 @@ func parseArgList(e string) (string, []*expr, map[string]*expr, string, error) {
}

// after the argument, trim any trailing spaces
e = strings.TrimLeftFunc(e, unicode.IsSpace)
e = skipWhitespace(e)

// We've consumed the entire buffer but the argument list isn't complete.
if len(e) == 0 {
Expand Down Expand Up @@ -676,7 +682,6 @@ FOR:
}

func parseString(s string) (string, string, error) {

if s[0] != '\'' && s[0] != '"' {
panic("string should start with open quote")
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/parser/parser_fuzz.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build gofuzz

package parser

func Fuzz(data []byte) int {
Expand Down
119 changes: 119 additions & 0 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,42 @@ import (
"reflect"
"testing"

"github.com/alecthomas/assert/v2"
"github.com/davecgh/go-spew/spew"
)

func TestSkipWhitespace(t *testing.T) {
testCases := []struct{ in, expected string }{
{
in: " ",
expected: "",
},
{
in: " foo",
expected: "foo",
},
{
in: " foo ",
expected: "foo ",
},
{
in: "\nfoo",
expected: "foo",
},
{
in: "\tfoo",
expected: "foo",
},
}

for _, tc := range testCases {
t.Run(tc.in, func(t *testing.T) {
out := skipWhitespace(tc.in)
assert.Equal(t, tc.expected, out)
})
}
}

func TestParseExpr(t *testing.T) {

tests := []struct {
Expand Down Expand Up @@ -427,6 +460,92 @@ func TestParseExpr(t *testing.T) {
argString: "func(\ng\r), \ns\t",
},
},
{
s: "foo.bar\n.baz\t",
e: &expr{
target: "foo.bar",
etype: EtName,
},
},
{
s: "absolute( baz )\n",
e: &expr{
target: "absolute",
etype: EtFunc,
args: []*expr{
{target: "baz"},
},
argString: " baz ",
},
},
{
s: "func1(\"example blah\")",
e: &expr{
target: "func1",
etype: EtFunc,
args: []*expr{
{
etype: EtString,
valStr: "example blah",
},
},
argString: "\"example blah\"",
},
},
{
s: "foobar(\n)",
e: &expr{
target: "foobar",
etype: EtFunc,
},
},
{
s: "foobar(asdf,\n\tzxcv,\n\tqwer\n)",
e: &expr{
target: "foobar",
etype: EtFunc,
args: []*expr{
{target: "asdf"},
{target: "zxcv"},
{target: "qwer"},
},
argString: "asdf,\n\tzxcv,\n\tqwer\n",
},
},
{
s: "func1(foo.bar)\n| func2(foo.baz)|\n func3(\n\tfunc4(asdf.zxcv.qwer)\n)",
e: &expr{
target: "func3",
etype: EtFunc,
args: []*expr{
{
target: "func2",
etype: EtFunc,
args: []*expr{
{
target: "func1",
etype: EtFunc,
args: []*expr{
{target: "foo.bar"},
},
argString: "foo.bar",
},
{target: "foo.baz"},
},
argString: "func1(foo.bar),foo.baz",
},
{
target: "func4",
etype: EtFunc,
args: []*expr{
{target: "asdf.zxcv.qwer"},
},
argString: "asdf.zxcv.qwer",
},
},
argString: "func2(func1(foo.bar),foo.baz),func4(asdf.zxcv.qwer)",
},
},
}

for _, ttr := range tests {
Expand Down
Loading
Loading