Browse Source

Fix FeatureJumpTimelineAge to guard against Divide by Zero (See #688)

pull/706/head
James Mills 1 week ago
parent
commit
f86f98e065
Signed by: prologic GPG Key ID: AC4C014F1440EBD6
  1. 7
      internal/utils.go
  2. 4
      internal/view_handlers.go

7
internal/utils.go

@ -1694,7 +1694,7 @@ func FilterTwtsFactory(conf *Config) FilterTwtsFunc {
// FilterTwtsAge calculates what page to scroll to, provided
// we want to see twts >= :age: hours old, and with :twtsPerPage:
// twts on each page.
func FilterTwtsAge(twts types.Twts, age int, twtsPerPage int) int {
func FilterTwtsAge(twts types.Twts, age, twtsPerPage int) int {
now := time.Now()
var twtIndex int
for i, twt := range twts {
@ -1703,7 +1703,10 @@ func FilterTwtsAge(twts types.Twts, age int, twtsPerPage int) int {
break
}
}
return int(twtIndex / twtsPerPage)
if twtsPerPage > 0 {
return int(twtIndex / twtsPerPage)
}
return 0
}
// CleanTwt cleans a twt's text, replacing new lines with spaces and

4
internal/view_handlers.go

@ -84,7 +84,9 @@ func (s *Server) TimelineHandler() httprouter.Handle {
if s.config.Features.IsEnabled(FeatureJumpTimelineAge) {
age := SafeParseInt(r.URL.Query().Get("t"), 0)
page = page + FilterTwtsAge(twts, age, s.config.TwtsPerPage)
if age > 0 {
page = page + FilterTwtsAge(twts, age, s.config.TwtsPerPage)
}
}
pager.SetPage(page)

Loading…
Cancel
Save