@@ -348,6 +348,10 @@ impl RawSeekPayload {
348348 pub ( crate ) fn decode < D : for < ' a > Deserialize < ' a > > ( & self ) -> AppResult < D > {
349349 decode_seek ( & self . 0 ) . map_err ( |_| bad_request ( "invalid seek parameter" ) )
350350 }
351+
352+ pub ( crate ) fn is_empty ( & self ) -> bool {
353+ self . 0 . is_empty ( )
354+ }
351355}
352356
353357/// Function to check if the request is blocked.
@@ -547,8 +551,8 @@ macro_rules! seek {
547551 impl $name {
548552 pub fn decode( & self , page: & Page ) -> AppResult <Option <[ <$name Payload >] >> {
549553 let encoded = match page {
550- Page :: Seek ( encoded) => encoded,
551- Page :: SeekBackward ( encoded) => encoded,
554+ Page :: Seek ( encoded) if !encoded . is_empty ( ) => encoded,
555+ Page :: SeekBackward ( encoded) if !encoded . is_empty ( ) => encoded,
552556 _ => return Ok ( None ) ,
553557 } ;
554558
@@ -780,6 +784,24 @@ mod tests {
780784 assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
781785 }
782786
787+ // empty string
788+ {
789+ let seek = Seek :: Id ;
790+ let pagination = PaginationOptions :: builder ( )
791+ . enable_seek ( true )
792+ . gather ( & mock ( "seek=" ) )
793+ . unwrap ( ) ;
794+ assert_eq ! ( seek. decode( & pagination. page) . unwrap( ) , None ) ;
795+
796+ // for backward
797+ let seek = Seek :: Id ;
798+ let pagination = PaginationOptions :: builder ( )
799+ . enable_seek_backward ( true )
800+ . gather ( & mock ( "seek=-" ) )
801+ . unwrap ( ) ;
802+ assert_eq ! ( seek. decode( & pagination. page) . unwrap( ) , None ) ;
803+ }
804+
783805 // Ensures it still encodes compactly with a field struct
784806 #[ derive( Debug , Default , Serialize , PartialEq ) ]
785807 struct NewTuple (
0 commit comments