Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: build_url may remove trailing slash #1080

Open
relikd opened this issue Oct 24, 2022 · 1 comment
Open

Bug: build_url may remove trailing slash #1080

relikd opened this issue Oct 24, 2022 · 1 comment

Comments

@relikd
Copy link
Contributor

relikd commented Oct 24, 2022

Found this while browsing through the source. Havent tested whether this is actually an issue, but:

lektor/lektor/utils.py

Lines 666 to 668 in dbae91e

_, last = url.split("/", 1)
if "." in last:
return url

shouldn't that actually be

last = url.split("/")[-1]
# or:
# if "." in url.split("/")[-1]:

Otherwise, an URL like this /path.my/page/2/ may wrongly remove the trailing slash.

@dairiki
Copy link
Contributor

dairiki commented Nov 5, 2022

I think you're right about the split.

It was probably meant to be

_, last = url.rsplit("/", 1)

Personally, I'd write it:

_, _, last = url.rpartition("/")

(Perhaps a larger refactor/cleanup is possible. Maybe using pathlib.PurePosixPath?)

As you say, it would be nice to have an actual test/demo of how it can go wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants