首页 > 解决方案 > How to safely encode cidr notation in url?

问题描述

I'm working on an application that does some basic network management. Due to constraints outside of the scope of this application, there's a need to encode a cidr block (eg 127.0.0.1/32) into the url. For instance, an endpoint route might look something like this post "/home/network/:user/:cidr". In most cases, one could easily send the cidr as a string in the payload but that is not an option here.

I know that . is a valid url character and that / can be encoded with %2F. Naively combining these and attempting to post against that endpoint like so: /home/network/janedoe/127.0.0.1%2F32 404ed which makes me think Sinatra isn't able to properly parse that url parameter. I've also tried using the URI module to encode the cidr string with no luck so far.

Perhaps there's an easier way to think about encoding the cidr block into the url that makes for easy extraction in the endpoint.

标签: rubysinatra

解决方案


推荐阅读