File tree Expand file tree Collapse file tree
examples/official-site/sqlpage/migrations
src/webserver/database/sqlpage_functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -549,21 +549,21 @@ VALUES (
549549
550550```sql
551551select ' ' text' ' AS component;
552- select sqlpage.is_path_matching(sqlpage.path(),' ' /api/%/%/% ' ' ) AS contents;
552+ select sqlpage.is_path_matching(sqlpage.path(),' ' /api/v1/user/%d/%s ' ' ) AS contents;
553553```
554554
555555#### Result
556556
557- `/api/v1/user/42`
557+ `/api/v1/user/42/name `
558558
559559#### Notes
560560
561561- The pattern is a list of segments separated by ' ' /' ' .
562562- If the path is NULL, or the pattern is NULL, it will return an empty string.
563563- If the path and pattern have different numbers of segments, it will return an empty string.
564564- If the path and pattern have the same number of segments, it will compare them segment by segment.
565- - If a segment in the pattern is ' ' %' ' , it will match any non-empty segment in the path .
566- - If a segment in the pattern is a string , it will match the corresponding segment in the path if they are equal .
565+ - If a segment in the pattern is ' ' %d ' ' , it will match any non-empty segment that is an integer .
566+ - If a segment in the pattern is ' ' %s ' ' , it will match any non-empty segment in the path.
567567- If all segments match, it will return the path.
568568- Otherwise, it will return an empty string.
569569'
Original file line number Diff line number Diff line change @@ -829,10 +829,15 @@ async fn is_path_matching<'a>(
829829 }
830830
831831 for ( ps, pat_s) in path_segments. iter ( ) . zip ( pattern_segments. iter ( ) ) {
832- if * pat_s == "%" {
832+ if * pat_s == "%s " {
833833 if ps. is_empty ( ) {
834834 return Some ( Cow :: Borrowed ( "" ) ) ;
835835 }
836+ } else if * pat_s == "%d" {
837+ let ps_decoded = percent_encoding:: percent_decode_str ( ps) . decode_utf8_lossy ( ) ;
838+ if ps_decoded. is_empty ( ) || ps_decoded. parse :: < i64 > ( ) . is_err ( ) {
839+ return Some ( Cow :: Borrowed ( "" ) ) ;
840+ }
836841 } else {
837842 let ps_decoded = percent_encoding:: percent_decode_str ( ps) . decode_utf8_lossy ( ) ;
838843 let pat_s_decoded = percent_encoding:: percent_decode_str ( pat_s) . decode_utf8_lossy ( ) ;
You can’t perform that action at this time.
0 commit comments