Skip to content

Commit 7c7d5f2

Browse files
authored
Return empty page if block inscription page request is out of range (#4439)
1 parent b7198d2 commit 7c7d5f2

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/subcommand/server.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,19 +1936,16 @@ impl Server {
19361936
AcceptJson(accept_json): AcceptJson,
19371937
) -> ServerResult {
19381938
task::block_in_place(|| {
1939-
let page_size = 100;
1940-
1941-
let page_index_usize = usize::try_from(page_index).unwrap_or(usize::MAX);
1942-
let page_size_usize = usize::try_from(page_size).unwrap_or(usize::MAX);
1939+
const PAGE_SIZE: usize = 100;
19431940

19441941
let mut inscriptions = index
19451942
.get_inscriptions_in_block(block_height)?
19461943
.into_iter()
1947-
.skip(page_index_usize.saturating_mul(page_size_usize))
1948-
.take(page_size_usize.saturating_add(1))
1944+
.skip(page_index.into_usize().saturating_mul(PAGE_SIZE))
1945+
.take(PAGE_SIZE.saturating_add(1))
19491946
.collect::<Vec<InscriptionId>>();
19501947

1951-
let more = inscriptions.len() > page_size_usize;
1948+
let more = inscriptions.len() > PAGE_SIZE;
19521949

19531950
if more {
19541951
inscriptions.pop();
@@ -1968,7 +1965,7 @@ impl Server {
19681965
inscriptions,
19691966
more,
19701967
page_index,
1971-
)?
1968+
)
19721969
.page(server_config)
19731970
.into_response()
19741971
})
@@ -6982,6 +6979,12 @@ next
69826979
StatusCode::OK,
69836980
r".*<a href=/inscription/[[:xdigit:]]{64}i0>.*</a>.*",
69846981
);
6982+
6983+
server.assert_response_regex(
6984+
"/inscriptions/block/102/2",
6985+
StatusCode::OK,
6986+
r".*<div class=thumbnails>\s*</div>.*",
6987+
);
69856988
}
69866989

69876990
#[test]

src/templates/inscriptions_block.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ impl InscriptionsBlockHtml {
1717
inscriptions: Vec<InscriptionId>,
1818
more_inscriptions: bool,
1919
page_index: u32,
20-
) -> Result<Self> {
21-
if page_index != 0 && inscriptions.is_empty() {
22-
return Err(anyhow!("page index {page_index} exceeds inscription count"));
23-
}
24-
25-
Ok(Self {
20+
) -> Self {
21+
Self {
2622
block,
2723
inscriptions,
2824
prev_block: block.checked_sub(1),
@@ -37,7 +33,7 @@ impl InscriptionsBlockHtml {
3733
} else {
3834
None
3935
},
40-
})
36+
}
4137
}
4238
}
4339

0 commit comments

Comments
 (0)