Skip to content

Commit

Permalink
Update wasilibs dependencies and use new FindN method for pm (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Apr 30, 2024
1 parent ceecaab commit 05c0efb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

go.work.sum
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ go 1.19

require (
github.com/corazawaf/coraza/v3 v3.0.4
github.com/magefile/mage v1.15.0
github.com/wasilibs/go-aho-corasick v0.5.0
github.com/wasilibs/go-libinjection v0.4.0
github.com/wasilibs/go-re2 v1.5.0-pre.1
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a
github.com/wasilibs/go-aho-corasick v0.6.0
github.com/wasilibs/go-libinjection v0.5.0
github.com/wasilibs/go-re2 v1.5.3-0.20240419072501-ea7825893288
golang.org/x/sync v0.3.0
)

require (
github.com/corazawaf/libinjection-go v0.1.2 // indirect
github.com/petar-dambovaliev/aho-corasick v0.0.0-20230725210150-fb29fc3c913e // indirect
github.com/tetratelabs/wazero v1.5.0 // indirect
github.com/tetratelabs/wazero v1.7.1 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ github.com/corazawaf/libinjection-go v0.1.2/go.mod h1:OP4TM7xdJ2skyXqNX1AN1wN5nN
github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6FI=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a h1:tdPcGgyiH0K+SbsJBBm2oPyEIOTAvLBwD9TuUwVtZho=
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
github.com/petar-dambovaliev/aho-corasick v0.0.0-20230725210150-fb29fc3c913e h1:POJco99aNgosh92lGqmx7L1ei+kCymivB/419SD15PQ=
github.com/petar-dambovaliev/aho-corasick v0.0.0-20230725210150-fb29fc3c913e/go.mod h1:EHPiTAKtiFmrMldLUNswFwfZ2eJIYBHktdaUTZxYWRw=
github.com/tetratelabs/wazero v1.5.0 h1:Yz3fZHivfDiZFUXnWMPUoiW7s8tC1sjdBtlJn08qYa0=
github.com/tetratelabs/wazero v1.5.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8=
github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand All @@ -19,10 +23,18 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/wasilibs/go-aho-corasick v0.5.0 h1:Y8G8eJ7usuC14sd93IxxnZH43K5Bz5C90a6LsAYGjmY=
github.com/wasilibs/go-aho-corasick v0.5.0/go.mod h1:1XPgz4lvFZA+Ytd8vfeCoqnwy4CSe0MxnLfRQJVqpJM=
github.com/wasilibs/go-aho-corasick v0.6.0 h1:/usYKOljcc+264yq7jzq1tsgyuS1F/cUzLE75TJIgsQ=
github.com/wasilibs/go-aho-corasick v0.6.0/go.mod h1:juBo/POXN3BapT9Bw93oxRQyyPha7AEu5SPUicPfLn4=
github.com/wasilibs/go-libinjection v0.4.0 h1:dr1Y/kM/gmoA7eSfdf+CvCcmzwsz2jVYjNdakgladDU=
github.com/wasilibs/go-libinjection v0.4.0/go.mod h1:zD7fNXKSaTKoSTmrfuP9Gc16alNEgwkZaHIeDDk3WWM=
github.com/wasilibs/go-libinjection v0.5.0 h1:ef+xIy0vLkZgvsyZevGDOFH3sq1aIrQI/8ImaCGDqDU=
github.com/wasilibs/go-libinjection v0.5.0/go.mod h1:i1Va/vm/PFDYZS1JHUd3Ab2bNk7Qol3W70bEWz7I3b4=
github.com/wasilibs/go-re2 v1.5.0-pre.1 h1:lJ0RGE6xp9hzFouzLrbEbzdZhpaqzg4rU2rA57eJLmI=
github.com/wasilibs/go-re2 v1.5.0-pre.1/go.mod h1:GAociXj3tyaHNF0zuZdhEHuODXbPsFpOdg8vuAAq2pw=
github.com/wasilibs/go-re2 v1.5.2 h1:fDO2TJrRzRrv3jD0gzOvmZ2UM4Yt9YXOEdLrlNc/Ies=
github.com/wasilibs/go-re2 v1.5.2/go.mod h1:UqqxQ1O99boQUm1r61H/IYGiGQOS/P88K7hU5nLNkEg=
github.com/wasilibs/go-re2 v1.5.3-0.20240419072501-ea7825893288 h1:cBACSN2hFe0FK7Z1bD8umZI+KbONYmXxBGmCOYPf3lU=
github.com/wasilibs/go-re2 v1.5.3-0.20240419072501-ea7825893288/go.mod h1:k8eqbC6uo9Y4ymW5EVU53/oPBAATUvMWIT1iTS2Bbcs=
github.com/wasilibs/nottinygc v0.4.0 h1:h1TJMihMC4neN6Zq+WKpLxgd9xCFMw7O9ETLwY2exJQ=
github.com/wasilibs/wazerox v0.0.0-20231218050519-52f5e22ee8b5 h1:7GQgc4ewesYeFF8bNxKvsT4q6ngGnGBkCFmwHs1ldwI=
github.com/wasilibs/wazerox v0.0.0-20231218050519-52f5e22ee8b5/go.mod h1:IQNVyA4d1hWIe23mlMMuqXjyWMdndgSlNx6FqBkwPsM=
Expand Down
26 changes: 0 additions & 26 deletions go.work.sum

This file was deleted.

15 changes: 2 additions & 13 deletions pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,15 @@ func (o *pm) Evaluate(tx plugintypes.TransactionState, value string) bool {
}

func pmEvaluate(matcher ahocorasick.AhoCorasick, tx plugintypes.TransactionState, value string) bool {
iter := matcher.Iter(value)

if !tx.Capturing() {
// Not capturing so just one match is enough.
return iter.Next() != nil
return len(matcher.FindN(value, 1)) > 0
}

var numMatches int
for {
m := iter.Next()
if m == nil {
break
}

for _, m := range matcher.FindN(value, 10) {
tx.CaptureField(numMatches, value[m.Start():m.End()])

numMatches++
if numMatches == 10 {
return true
}
}

return numMatches > 0
Expand Down

0 comments on commit 05c0efb

Please sign in to comment.