* querylog: case-insensitive search by domain name

Close #1828

Squashed commit of the following:

commit 347aff1f8c5293bd06ecc0693970fe447b6e2c75
Merge: f07c8dc0 9df7aba9
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Fri Jul 3 12:10:02 2020 +0300

    Merge remote-tracking branch 'origin/master' into 1828-qlog-case-insens

commit f07c8dc0665585ce00c415293c47c5a8c9724881
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Fri Jul 3 12:09:49 2020 +0300

    minor

commit 512c7acd48f649a0d11b4fef66a1351fcd19635b
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Thu Jul 2 19:01:43 2020 +0300

    minor

commit 9f5700af56340c38a2d892101e32959702816205
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Thu Jul 2 16:53:56 2020 +0300

    * querylog: case-insensitive search by domain name
This commit is contained in:
Simon Zolin 2020-07-03 12:21:09 +03:00
parent 9df7aba9e1
commit 21dfb5ffe8
2 changed files with 10 additions and 6 deletions

View File

@ -59,7 +59,7 @@ func TestQueryLog(t *testing.T) {
params.searchCriteria = append(params.searchCriteria, searchCriteria{ params.searchCriteria = append(params.searchCriteria, searchCriteria{
criteriaType: ctDomainOrClient, criteriaType: ctDomainOrClient,
strict: true, strict: true,
value: "test.example.org", value: "TEST.example.org",
}) })
entries, _ = l.search(params) entries, _ = l.search(params)
assert.Equal(t, 1, len(entries)) assert.Equal(t, 1, len(entries))
@ -70,7 +70,7 @@ func TestQueryLog(t *testing.T) {
params.searchCriteria = append(params.searchCriteria, searchCriteria{ params.searchCriteria = append(params.searchCriteria, searchCriteria{
criteriaType: ctDomainOrClient, criteriaType: ctDomainOrClient,
strict: false, strict: false,
value: "example.org", value: "example.ORG",
}) })
entries, _ = l.search(params) entries, _ = l.search(params)
assert.Equal(t, 3, len(entries)) assert.Equal(t, 3, len(entries))

View File

@ -62,11 +62,13 @@ func (c *searchCriteria) quickMatchJSONValue(line string, propertyName string) b
if len(val) == 0 { if len(val) == 0 {
return false return false
} }
val = strings.ToLower(val)
searchVal := strings.ToLower(c.value)
if c.strict && c.value == val { if c.strict && searchVal == val {
return true return true
} }
if !c.strict && strings.Contains(val, c.value) { if !c.strict && strings.Contains(val, searchVal) {
return true return true
} }
@ -78,10 +80,12 @@ func (c *searchCriteria) quickMatchJSONValue(line string, propertyName string) b
func (c *searchCriteria) match(entry *logEntry) bool { func (c *searchCriteria) match(entry *logEntry) bool {
switch c.criteriaType { switch c.criteriaType {
case ctDomainOrClient: case ctDomainOrClient:
if c.strict && entry.QHost == c.value { qhost := strings.ToLower(entry.QHost)
searchVal := strings.ToLower(c.value)
if c.strict && qhost == searchVal {
return true return true
} }
if !c.strict && strings.Contains(entry.QHost, c.value) { if !c.strict && strings.Contains(qhost, searchVal) {
return true return true
} }