mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-28 13:41:21 +00:00
Merge pull request #1689 from tendermint/1688-tx-search-panic
validate per_page before page
This commit is contained in:
commit
d2259696af
@ -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
|
||||
|
@ -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},
|
||||
|
@ -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…
x
Reference in New Issue
Block a user