[Flask] Flask path route variable with a dot between two forward slashes

Rodrigo Ramírez Norambuena decipher.hk at gmail.com
Tue Nov 24 20:51:06 EST 2015


I thinks is as browser resolve the URL

testing with your code example like


@app.route('/url/<path:url>', methods=['GET'])
def get_url(url):
    app.logger.debug(url)
    return jsonify(
        url= url,
    )

Log from request from a browser
192.168.10.1 - - [24/Nov/2015 22:46:17] "GET /url/http://met.no/Nyheter/Fase+C:+Ekstremv%C3%A6ret+Petra+p%C3%A5g%C3%A5r.b7C_xdrSX6.ips HTTP/1.1" 200 -

Using  curl
 curl 'http://192.168.10.2:5000/url/http://met.no/Nyheter/./Fase+C:+Ekstremv%C3%A6ret+Petra+p%C3%A5g%C3%A5r.b7C_xdrSX6.ips'
{
  "url": "http://met.no/Nyheter/./Fase+C:+Ekstremv\u00e6ret+Petra+p\u00e5g\u00e5r.b7C_xdrSX6.ips"
}%                                            

192.168.10.1 - - [24/Nov/2015 22:46:25] "GET /url/http://met.no/Nyheter/./Fase+C:+Ekstremv%C3%A6ret+Petra+p%C3%A5g%C3%A5r.b7C_xdrSX6.ips HTTP/1.1" 200 -

Regards,

November 24 2015 11:06 AM, "Francisco Roque" <francisco at roque.com.pt> wrote:
> Hi all, 
> 
> I am trying to capture an url from a flask request. All works fine except when the url has a dot in
> between two forward slashes, for example: 
> 
> http://met.no/Nyheter/./Fase+C:+Ekstremværet+Petra+pågår.b7C_xdrSX6.ips
> 
> The route used is below:
> 
> @app.route('/url/<path:url>', methods=['GET'])
> def get_url(url):
> return url
> 
> I understand flask is somehow resolving relative urls and ./ might mean the current directory, but
> how can I make it so the url is taken as is?
> 
> Best,
> Francisco


More information about the Flask mailing list