◐ Shell
clean mode source ↗

bpo-38863: Fix a bug of is_cgi() in http.server by kkangshawn · Pull Request #17292 · python/cpython

@kkangshawn

is_cgi() function of http.server library does not correctly separate
given path for cgi script into a directory and a file part. is_cgi() in
CGIHTTPRequestHandler class separates given path into (dir, rest) then
checks if dir is in cgi_directories. However, it divides based on the
first seen '/', multi-level directories like /sub/dir/cgi-bin/hello.py
is divided into head=/sub, rest=dir/cgi-bin/hello.py then check whether
'/sub' exists in cgi_directories = [..., '/sub/dir/cgi-bin'].
If the function divides by last seen '/', it works correctly as
head=/sub/dir/cgi-bin, rest=hello.py

Signed-off-by: Siwon Kang <kkangshawn@gmail.com>