osalvador / dbax-lite

PLSQL framework for MVC Web Development
https://dbax-project.com
GNU Lesser General Public License v3.0
9 stars 4 forks source link

Router: Optional Parameters #3

Closed mcardia closed 6 years ago

mcardia commented 6 years ago

Hi! Great project!

A doubt: How can I use optional parameters in router without last slash?

Example: My route is ...if route_.get ('img/{img_id}/{d}?', p) then...

app?p=/img/20137/275x275 works app?p=/img/20137/ works app?p=/img/20137 don't work.

I tried: ...if route_.get ('img/{img_id}/?{d}?', p) then... ...if route_.get ('img/{img_id}(/{d})?', p) then... ...if route_.get ('img/{img_id}/?({d})?', p) then...

neither worked...

Thank you.

osalvador commented 6 years ago

Hi @mcardia

Thanks for your comment. You just found a bug in the router_.

I just updated the master branch with the fix.

It's a simple line of code, you can update it yourself instead of waiting for a new release.

https://github.com/osalvador/dbax-lite/commit/8ecac64cc278d8afc70cf08f2b01a3a13b900051#diff-71321135cd1c5661ae5d9d5880adc328

mcardia commented 6 years ago

Thank you for the fast reply. now works if i add ? do the dash. Like this: elsif route_.get ('img/{id}/?{d}?', p) then

The way it is in documentation still don´t work. elsif route_.get ('img/{id}/{d}?', p) then

Could be any side effects using the way i did?

Thanks.

osalvador commented 6 years ago

Hi @mcardia

Indeed, that is the correct thing to do. I have to update the documentation to make it clear.

I have passed some tests and I have not found any side effects, I added more test and these are the results:

**********
Routing with optional parameters. The documentation example
**********
- The input path is `user` the regular expression: user/?{Id}?/?{Name}?
   l_param ('id') =
   l_param ('name') =
   Pass
- The input path is `user/` the regular expression: user/?{Id}?/?{Name}?
   l_param ('id') =
   l_param ('name') =
   Pass
- The input path is `user/id` the regular expression: user/?{Id}?/?{Name}?
   l_param ('id') = id
   l_param ('name') =
   Pass
- The input path is `user/id/` the regular expression: user/?{Id}?/?{Name}?
   l_param ('id') = id
   l_param ('name') =
   Pass
- The input path is `user/id/name` the regular expression: user/?{Id}?/?{Name}?
   l_param ('id') = id
   l_param ('name') = name
   Pass
- The input path is `user/id/name/` the regular expression: user/?{Id}?/?{Name}?
   l_param ('id') = id
   l_param ('name') = name
   Pass