Skip to content

Commit

Permalink
丢弃丑陋的re2/re2.cc:231: Error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
yhy0 committed Jul 3, 2024
1 parent c230243 commit 96f4c69
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wappalyzer
import (
"fmt"
"github.com/dlclark/regexp2"
"os"

regexp "github.com/wasilibs/go-re2"
"strconv"
Expand Down Expand Up @@ -44,7 +45,19 @@ func ParsePattern(pattern string) (*ParsedPattern, error) {
// regexPattern = strings.ReplaceAll(regexPattern, "__escapedPlus__", "\\+")

var err error

// 保存原始的标准错误
originalStderr := os.Stderr
// 创建一个丢弃输出的 writer , 丢弃丑陋的 re2/re2.cc:231: Error parsing
devNull, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
// 将标准错误重定向到 devNull
os.Stderr = devNull
p.regex, err = regexp.Compile("(?i)" + regexPattern)
// 恢复原始标准错误
os.Stderr = originalStderr
if err != nil {
// 好些正则,不论是使用 go 的 regexp 包,还是 github.com/wasilibs/go-re2 都会出现解析错误的情况,这里使用 github.com/dlclark/regexp2 看看情况
reg2, err := regexp2.Compile(regexPattern, 0)
Expand Down

0 comments on commit 96f4c69

Please sign in to comment.