Repository: ysugimoto/falco
Pull request #88 (2022-07-21 09:26:19)

revert #66
#66 could not be reverted so I revert its implementations manually.


Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 5ae6772..24ef6fd 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -16,8 +16,6 @@ jobs:
       uses: actions/setup-go@v2
       with:
         go-version: 1.17.5
-    - name: Install dependencies
-      run: make linux-deps
     - name: Run tests
       run: make test
     - name: Lint programs
diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml
index caa7a83..f89f415 100644
--- a/.github/workflows/pullrequest.yml
+++ b/.github/workflows/pullrequest.yml
@@ -13,8 +13,6 @@ jobs:
       uses: actions/setup-go@v2
       with:
         go-version: 1.17.5
-    - name: Install dependencies
-      run: make linux-deps
     - name: Run tests
       run: make test
     - name: Lint programs
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 6c8f8a6..0c9dccf 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -15,8 +15,6 @@ jobs:
         uses: actions/setup-go@v2
         with:
           go-version: 1.17.5
-      - name: Install dependencies
-        run: make linux-deps
       - name: Run tests
         run: make test
       - name: Lint programs
diff --git a/Makefile b/Makefile
index 9f7bdfc..87d666a 100644
--- a/Makefile
+++ b/Makefile
@@ -8,19 +8,13 @@ generate:
 test: generate
 	go list ./... | xargs go test
 
-darwin-deps:
-	brew list pcre || brew install pcre
-
-linux-deps:
-	sudo apt-get install -y libpcre3-dev
-
 linux:
-	GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build \
+	GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \
 			 -ldflags "-X main.version=$(BUILD_VERSION)" \
 			 -o dist/falco-linux-amd64 ./cmd/falco
 
 darwin_amd64:
-	GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build \
+	GOOS=darwin GOARCH=amd64 go build \
 			 -ldflags "-X main.version=$(BUILD_VERSION)" \
 			 -o dist/falco-darwin-amd64 ./cmd/falco
 
diff --git a/README.md b/README.md
index d8e7960..cf56dfe 100644
--- a/README.md
+++ b/README.md
@@ -38,19 +38,6 @@ Download binary from [releases page](https://github.com/ysugimoto/falco/releases
 
 Or compile it yourself with `go install github.com/ysugimoto/falco/cmd/falco@latest`.
 
-## Compiling
-[Fastly](https://developer.fastly.com/reference/vcl/regex/) supports [PCRE regular expressions](https://www.pcre.org/). To be able to parse regex you need to install the PCRE library on your machine before compiling the binary.
-
-For mac:
-```
-make darwin-deps
-``` 
-
-For Linux
-```
-make linux-deps
-```
-
 ## Usage
 
 Command help displays following:
diff --git a/go.mod b/go.mod
index ebc3855..b805bd2 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,6 @@ go 1.16
 
 require (
 	github.com/fatih/color v1.12.0
-	github.com/gijsbers/go-pcre v0.0.0-20161214203829-a84f3096ab3c
 	github.com/goccy/go-yaml v1.8.9
 	github.com/google/go-cmp v0.5.6
 	github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
diff --git a/go.sum b/go.sum
index 4811c37..a19e93e 100644
--- a/go.sum
+++ b/go.sum
@@ -2,8 +2,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
 github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
 github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
-github.com/gijsbers/go-pcre v0.0.0-20161214203829-a84f3096ab3c h1:o5z/Stj4aWUiDiCVFdEOgXcwNF+Z7mQSlvDTaWBK98Q=
-github.com/gijsbers/go-pcre v0.0.0-20161214203829-a84f3096ab3c/go.mod h1:Bd83Kcti1U5OMXYYTjilhd6os+l6AmlTMVbDtaBvycQ=
 github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
 github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
diff --git a/linter/linter.go b/linter/linter.go
index d32cb17..63276c9 100644
--- a/linter/linter.go
+++ b/linter/linter.go
@@ -3,9 +3,9 @@ package linter
 import (
 	"fmt"
 	"net"
+	"regexp"
 	"strings"
 
-	regexp "github.com/gijsbers/go-pcre"
 	"github.com/ysugimoto/falco/ast"
 	"github.com/ysugimoto/falco/context"
 	"github.com/ysugimoto/falco/token"
@@ -1357,7 +1357,7 @@ func (l *Linter) lintInfixExpression(exp *ast.InfixExpression, ctx *context.Cont
 		}
 		// And, if right expression is STRING, regex must be valid
 		if v, ok := exp.Right.(*ast.String); ok {
-			if _, err := regexp.Compile(v.Value, regexp.BSR_UNICODE); err != nil {
+			if _, err := regexp.Compile(strings.ReplaceAll(v.Value, "\\", "\\\\")); err != nil {
 				err := &LintError{
 					Severity: ERROR,
 					Token:    exp.Right.GetMeta().Token,


Test patch:
diff --git a/linter/linter_test.go b/linter/linter_test.go
index 0ed8d00..2e4e2a3 100644
--- a/linter/linter_test.go
+++ b/linter/linter_test.go
@@ -1070,36 +1070,6 @@ sub foo {
 }`
 		assertError(t, input)
 	})
-
-	t.Run("pass with PCRE expression", func(t *testing.T) {
-		input := `
-sub foo {
-	if (req.http.Host ~ "(?i)^word") {
-		restart;
-	}
-}`
-		assertNoError(t, input)
-	})
-
-	t.Run("pass with expression that has backslash", func(t *testing.T) {
-		input := `
-sub foo {
-	if (req.http.User-Agent ~ "\(compatible.?; Googlebot/2.1.?; \+http://www.google.com/bot.html") {
-		restart;
-	}
-}`
-		assertNoError(t, input)
-	})
-
-	t.Run("pass with PCRE expression that has backslash", func(t *testing.T) {
-		input := `
-sub foo {
-	if (req.http.User-Agent ~ "(?i)windows\ ?ce") {
-		restart;
-	}
-}`
-		assertNoError(t, input)
-	})
 }
 
 func TestLintRegexNotOperator(t *testing.T) {