Skip to content

Commit

Permalink
refactor: invert -> inverte
Browse files Browse the repository at this point in the history
  • Loading branch information
anfragment committed Nov 17, 2023
1 parent c8111ea commit ad53bce
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions filter/ruletree/rule/contenttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

type contentTypeModifier struct {
contentType string
invert bool
inverted bool
}

func (m *contentTypeModifier) Parse(modifier string) error {
if modifier[0] == '~' {
m.invert = true
m.inverted = true
modifier = modifier[1:]
}
m.contentType = modifier
Expand Down Expand Up @@ -45,12 +45,12 @@ func (m *contentTypeModifier) ShouldMatch(req *http.Request) bool {
}
contentType, ok := secFetchDestMap[secFetchDest]
if m.contentType == "other" {
if m.invert {
if m.inverted {
return ok
}
return !ok
}
if m.invert {
if m.inverted {
return contentType != m.contentType
}
return contentType == m.contentType
Expand Down
12 changes: 6 additions & 6 deletions filter/ruletree/rule/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func (m *domainModifier) ShouldMatch(req *http.Request) bool {
}

type domainModifierEntry struct {
invert bool
regular string
tld string
regex *regexp.Regexp
inverted bool
regular string
tld string
regex *regexp.Regexp
}

func (m *domainModifierEntry) Parse(entry string) error {
if entry[0] == '~' {
m.invert = true
m.inverted = true
entry = entry[1:]
}
if entry[0] == '/' && entry[len(entry)-1] == '/' {
Expand All @@ -76,7 +76,7 @@ func (m *domainModifierEntry) MatchDomain(domain string) bool {
} else if m.regex != nil {
matches = m.regex.MatchString(domain)
}
if m.invert {
if m.inverted {
return !matches
}
return matches
Expand Down
10 changes: 5 additions & 5 deletions filter/ruletree/rule/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func (m *methodModifier) ShouldMatch(req *http.Request) bool {
}

type methodModifierEntry struct {
method string
invert bool
method string
inverted bool
}

func (m *methodModifierEntry) Parse(modifier string) error {
if modifier[0] == '~' {
m.invert = true
m.inverted = true
modifier = modifier[1:]
}
m.method = modifier
Expand All @@ -52,7 +52,7 @@ func (m *methodModifierEntry) Parse(modifier string) error {

func (m *methodModifierEntry) MatchMethod(method string) bool {
if strings.ToLower(method) == m.method {
return !m.invert
return !m.inverted
}
return m.invert
return m.inverted
}
10 changes: 5 additions & 5 deletions filter/ruletree/rule/thirdparty.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (

// https://adguard.com/kb/general/ad-filtering/create-own-filters/#third-party-modifier
type thirdPartyModifier struct {
invert bool
inverted bool
}

func (m *thirdPartyModifier) Parse(modifier string) error {
if modifier[0] == '~' {
m.invert = true
m.inverted = true
}
return nil
}

func (m *thirdPartyModifier) ShouldMatch(req *http.Request) bool {
if req.Header.Get("Sec-Fetch-Site") == "cross-site" {
return !m.invert
return !m.inverted
}
if referer := req.Header.Get("Referer"); referer != "" {
host := req.Host
Expand All @@ -32,9 +32,9 @@ func (m *thirdPartyModifier) ShouldMatch(req *http.Request) bool {
}
refererHost := refererURL.Hostname()
if strings.HasSuffix(refererHost, host) {
return m.invert
return m.inverted
}
return !m.invert
return !m.inverted
}
return false
}

0 comments on commit ad53bce

Please sign in to comment.