Skip to content

Commit

Permalink
Merge pull request #146 from scrapli/fix/ansipattern-once
Browse files Browse the repository at this point in the history
fix: hide ansi pattern in utils behind a sync.Once like other regexps
  • Loading branch information
carlmontanari authored Jul 31, 2023
2 parents bf53afb + 3a67da3 commit f71219f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion driver/netconf/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ type Driver struct {

serverCapabilities []string
sessionID uint64
ServerEcho *bool

messageID int

Expand Down
10 changes: 7 additions & 3 deletions util/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ package util
import (
"bytes"
"regexp"
"sync"
)

const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?" +
"\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"

var ansiPattern *regexp.Regexp //nolint: gochecknoglobals
var (
ansiPattern *regexp.Regexp //nolint: gochecknoglobals
ansiPatternOnce sync.Once //nolint: gochecknoglobals
)

func getAnsiPattern() *regexp.Regexp {
if ansiPattern == nil {
ansiPatternOnce.Do(func() {
ansiPattern = regexp.MustCompile(ansi)
}
})

return ansiPattern
}
Expand Down

0 comments on commit f71219f

Please sign in to comment.