Skip to content

Commit

Permalink
Fix confusion between index and limit in URL parse
Browse files Browse the repository at this point in the history
  • Loading branch information
dullgiulio committed Apr 8, 2015
1 parent bc473c1 commit d04a0f9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
5 changes: 4 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ func (c *caches) run() {
continue
}

if r.limit == 0 || r.limit > lfiles {
if r.limit == 0 {
r.limit = 1
}
if r.limit > lfiles {
r.limit = lfiles
}

Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type config struct {

func newConfig() *config {
keys := makeIndexKeys()
keys.add("", keyTypeAny)
keys.add("", keyTypeNormal)
keys.add("from", keyTypeAddr)
keys.add("to", keyTypeAddr)

Expand Down
10 changes: 7 additions & 3 deletions mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ func (m *mailIndexer) cacheEntries(file mailFile, msg *mail.Message) []cacheEntr

for key, kt := range m.keys {
headerKey, val := headers.get(key)
if val == nil {
continue
}

switch kt {
case keyTypeAny:
Expand All @@ -86,6 +83,13 @@ func (m *mailIndexer) cacheEntries(file mailFile, msg *mail.Message) []cacheEntr
log.Print(file, ": error parsing header ", headerKey, ": ", err)
}
default:
if val == nil && key == "" {
entries = append(entries, cacheEntry{
name: "", key: "", value: file,
})
continue
}

for _, v := range val {
entries = append(entries, cacheEntry{
name: key,
Expand Down
5 changes: 2 additions & 3 deletions urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func makeCacheRequest(url string) (*cacheRequest, error) {
}

if len(parts) < 2 {
cr.limit = 1
return cr, nil
}

Expand Down Expand Up @@ -100,10 +99,10 @@ func makeCacheRequest(url string) (*cacheRequest, error) {
return cr, nil
}

if limit, err := strconv.ParseInt(parts[1], 10, 32); err != nil {
if index, err := strconv.ParseInt(parts[1], 10, 32); err != nil {
return nil, err
} else {
cr.limit = int(limit)
cr.index = int(index)
return cr, nil
}

Expand Down
14 changes: 7 additions & 7 deletions urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

func TestUrlLatest(t *testing.T) {
cr, err := makeCacheRequest("/latest/1")
cr, err := makeCacheRequest("/latest/2")
if err != nil {
t.Error("No error expected, got: ", err)
}
if cr.limit != 1 {
if cr.limit != 0 {
t.Error("Limit is not set correctly")
}
if cr.index != 0 {
if cr.index != 2 {
t.Error("Index is not set correctly")
}
if cr.oldest == true {
Expand All @@ -25,10 +25,10 @@ func TestUrlOldest(t *testing.T) {
if err != nil {
t.Error("No error expected, got: ", err)
}
if cr.limit != 17 {
if cr.limit != 0 {
t.Error("Limit is not set correctly")
}
if cr.index != 0 {
if cr.index != 17 {
t.Error("Index is not set correctly")
}
if cr.oldest != true {
Expand Down Expand Up @@ -73,10 +73,10 @@ func TestUrlFrom(t *testing.T) {
if err != nil {
t.Error("No error expected, got: ", err)
}
if cr.limit != 17 {
if cr.limit != 0 {
t.Error("Limit is not set correctly")
}
if cr.index != 0 {
if cr.index != 17 {
t.Error("Index is not set correctly")
}
if cr.oldest != true {
Expand Down

0 comments on commit d04a0f9

Please sign in to comment.