Browse Source

validate per_page before page

plus an additional check just in case
Closes #1688
pull/1689/head
Anton Kaliaev 7 years ago
parent
commit
2ce8179c8b
No known key found for this signature in database GPG Key ID: 7B6881D965918214
3 changed files with 7 additions and 1 deletions
  1. +4
    -0
      rpc/core/pipe.go
  2. +2
    -0
      rpc/core/pipe_test.go
  3. +1
    -1
      rpc/core/tx.go

+ 4
- 0
rpc/core/pipe.go View File

@ -125,6 +125,10 @@ func SetEventBus(b *types.EventBus) {
}
func validatePage(page, perPage, totalCount int) int {
if perPage < 1 {
return 1
}
pages := ((totalCount - 1) / perPage) + 1
if page < 1 {
page = 1


+ 2
- 0
rpc/core/pipe_test.go View File

@ -15,6 +15,8 @@ func TestPaginationPage(t *testing.T) {
page int
newPage int
}{
{0, 0, 1, 1},
{0, 10, 0, 1},
{0, 10, 1, 1},
{0, 10, 2, 1},


+ 1
- 1
rpc/core/tx.go View File

@ -189,8 +189,8 @@ func TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSear
}
totalCount := len(results)
page = validatePage(page, perPage, totalCount)
perPage = validatePerPage(perPage)
page = validatePage(page, perPage, totalCount)
skipCount := (page - 1) * perPage
apiResults := make([]*ctypes.ResultTx, cmn.MinInt(perPage, totalCount-skipCount))


Loading…
Cancel
Save