@@ -272,6 +272,35 @@ describe("GET /api/search", () => {
272272 expect ( chain . range ) . toHaveBeenCalledWith ( 0 , 9 ) ;
273273 } ) ;
274274
275+ it ( "truncates fractional page values before calculating ranges" , async ( ) => {
276+ const chain = chainResult ( { data : [ ] , error : null , count : 0 } ) ;
277+ mockFrom . mockReturnValue ( chain ) ;
278+
279+ const res = await GET (
280+ makeRequest ( { q : "test" , type : "gigs" , page : "2.9" , limit : "5" } )
281+ ) ;
282+ const json = await res . json ( ) ;
283+
284+ expect ( res . status ) . toBe ( 200 ) ;
285+ expect ( chain . range ) . toHaveBeenCalledWith ( 5 , 9 ) ;
286+ expect ( json . results . gigs . page ) . toBe ( 2 ) ;
287+ } ) ;
288+
289+ it ( "caps huge page values before calculating ranges" , async ( ) => {
290+ const chain = chainResult ( { data : [ ] , error : null , count : 0 } ) ;
291+ mockFrom . mockReturnValue ( chain ) ;
292+
293+ const res = await GET (
294+ makeRequest ( { q : "test" , type : "gigs" , page : "1e308" , limit : "999" } )
295+ ) ;
296+ const json = await res . json ( ) ;
297+
298+ expect ( res . status ) . toBe ( 200 ) ;
299+ expect ( chain . range ) . toHaveBeenCalledWith ( 4999950 , 4999999 ) ;
300+ expect ( json . results . gigs . page ) . toBe ( 100000 ) ;
301+ expect ( json . results . gigs . limit ) . toBe ( 50 ) ;
302+ } ) ;
303+
275304 // ── SQL character escaping ────────────────────────────────────
276305
277306 it ( "escapes % in search query" , async ( ) => {
0 commit comments