Skip to content

Commit 301f761

Browse files
authored
Merge pull request #551 from bookingcom/dzhdanov/PR771_backport
Backport of \n and spaces in queries from go-graphite carbonapi
2 parents 1a0b585 + f96c45a commit 301f761

File tree

34 files changed

+2895
-24
lines changed

34 files changed

+2895
-24
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
go-version: [ 1.23.x, 1.24.x, tip ]
12+
go-version: [1.24.x, 1.25.x, tip]
1313
steps:
1414
- name: Set up Go stable
1515
if: matrix.go-version != 'tip'
@@ -32,17 +32,17 @@ jobs:
3232
- name: test
3333
run: make test
3434
- name: govulncheck
35-
if: matrix.go-version != 'tip'
35+
if: matrix.go-version == '1.25.x'
3636
uses: golang/govulncheck-action@v1
3737
with:
3838
go-version-input: ${{ matrix.go-version }}
3939
check-latest: true
4040
go-package: ./...
4141
- name: golangci-lint
42-
if: matrix.go-version == '1.24.x'
43-
uses: golangci/golangci-lint-action@v8
42+
if: matrix.go-version == '1.25.x'
43+
uses: golangci/golangci-lint-action@v9
4444
with:
45-
version: v2.1.6
45+
version: v2.6.1
4646
- name: integration test
47-
if: matrix.go-version == '1.24.x'
47+
if: matrix.go-version == '1.25.x'
4848
run: tests/system_test.sh

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23.0
44

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

3334
require (
3435
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect
36+
github.com/alecthomas/repr v0.4.0 // indirect
3537
github.com/beorn7/perks v1.0.1 // indirect
3638
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3739
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 // indirect
@@ -44,6 +46,7 @@ require (
4446
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
4547
github.com/felixge/httpsnoop v1.0.3 // indirect
4648
github.com/golang/protobuf v1.5.3 // indirect
49+
github.com/hexops/gotextdiff v1.0.3 // indirect
4750
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4851
github.com/prometheus/client_model v0.6.2 // indirect
4952
github.com/prometheus/common v0.66.1 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ github.com/JaderDias/movingmedian v0.0.0-20220813210630-d8c6b6de8835 h1:mbxQnovj
77
github.com/JaderDias/movingmedian v0.0.0-20220813210630-d8c6b6de8835/go.mod h1:zsfWLaDctbM7aV1TsQAwkVswuKQ0k7PK4rjC1VZqpbI=
88
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTNVW4PtpQb8aKA4Pjy0CdJHEqvFbAnvR5m2g=
99
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY=
10+
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
11+
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
12+
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
13+
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
1014
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
1115
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
1216
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -100,6 +104,8 @@ github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
100104
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
101105
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
102106
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
107+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
108+
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
103109
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
104110
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
105111
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

pkg/expr/functions/cairo/cairo_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build cairo
2-
// +build cairo
32

43
package cairo
54

pkg/expr/functions/cairo/png/cairo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build cairo
2-
// +build cairo
32

43
package png
54

pkg/expr/functions/cairo/png/pixel_ratio.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build cairo
2-
// +build cairo
32

43
package png
54

pkg/expr/functions/cairo/png/png.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !cairo
2-
// +build !cairo
32

43
package png
54

pkg/expr/types/cairo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build cairo
2-
// +build cairo
32

43
package types
54

pkg/expr/types/png.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !cairo
1+
//go:build !cairo
22

33
package types
44

pkg/parser/parser.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,19 @@ func (e *expr) insertFirstArg(exp *expr) error {
332332
return nil
333333
}
334334

335-
func parseExprWithoutPipe(e string) (Expr, string, error) {
336-
// skip whitespace
337-
for len(e) > 1 && unicode.IsSpace(rune(e[0])) {
338-
e = e[1:]
335+
func skipWhitespace(e string) string {
336+
skipTo := len(e)
337+
for i, r := range e {
338+
if !unicode.IsSpace(r) {
339+
skipTo = i
340+
break
341+
}
339342
}
343+
return e[skipTo:]
344+
}
345+
346+
func parseExprWithoutPipe(e string) (Expr, string, error) {
347+
e = skipWhitespace(e)
340348

341349
if len(e) == 0 {
342350
return nil, "", ErrMissingExpr
@@ -393,9 +401,7 @@ func ParseExpr(e string) (Expr, string, error) {
393401
}
394402

395403
func pipe(exp *expr, e string) (*expr, string, error) {
396-
for len(e) > 1 && unicode.IsSpace(rune(e[0])) {
397-
e = e[1:]
398-
}
404+
e = skipWhitespace(e)
399405

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

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

521527
// after the argument, trim any trailing spaces
522-
e = strings.TrimLeftFunc(e, unicode.IsSpace)
528+
e = skipWhitespace(e)
523529

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

678684
func parseString(s string) (string, string, error) {
679-
680685
if s[0] != '\'' && s[0] != '"' {
681686
panic("string should start with open quote")
682687
}

0 commit comments

Comments
 (0)