We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
We have an internal api that cares about whether the url ends in a '/'. This may be a poor design, but such things exist.
When a path is added to a url with the / operator, the final '/' is stripped.
import yarl from yarl import URL url = URL(f'http://example.com') / 'foo/bar/baz/' print(url)
from yarl import URL url = URL(f'http://example.com') / 'foo/bar/baz/' assert str(url).endswith('/'), "where did my slash go?" url = URL(f'http://example.com') / 'foo' / 'bar'/ 'baz' / '' assert str(url).endswith('/'), "still no slash?"
The final slash should be preserved when appending a path with the truediv operator. This would be in accord with the Principle of Least Surprise.
>>> from yarl import URL >>> url = URL(f'http://example.com') / 'foo/bar/baz/' >>> assert str(url).endswith('/'), "where did my slash go?" Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError: where did my slash go? >>> >>> url = URL(f'http://example.com') / 'foo' / 'bar'/ 'baz' / '' >>> assert str(url).endswith('/'), "still no slash?" Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError: still no slash?
$ python --version Python 3.11.4
$ python -m pip show multidict Name: multidict Version: 6.0.4 Summary: multidict implementation Home-page: https://github.com/aio-libs/multidict Author: Andrew Svetlov Author-email: [email protected] License: Apache 2 Location: /home/matthew/venvs/wxp/lib/python3.11/site-packages Requires: Required-by: aiohttp, yarl
$ python -m pip show yarl Name: yarl Version: 1.9.2 Summary: Yet another URL library Home-page: https://github.com/aio-libs/yarl/ Author: Andrew Svetlov Author-email: [email protected] License: Apache-2.0 Location: /home/matthew/venvs/wxp/lib/python3.11/site-packages Requires: idna, multidict Required-by: aio-pika, aiohttp, aiormq
$ uname -a Linux mattswxp 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
No response
The text was updated successfully, but these errors were encountered:
Regression from 1.8.2
>>> yarl.__version__ '1.8.2' >>> URL("https://example.inv/Foo/Bar/") / "test/" URL('https://example.inv/Foo/Bar/test/')
"bi-sected" this to #704 @mjpieters want to assist?
Sorry, something went wrong.
So does pathlib though:
>>> print(pathlib.Path("foo") / "bar/baz/") foo/bar/baz
Made a fix in #1023
4bededd
Successfully merging a pull request may close this issue.
Describe the bug
We have an internal api that cares about whether the url ends in a '/'.
This may be a poor design, but such things exist.
When a path is added to a url with the / operator, the final '/' is stripped.
To Reproduce
Expected behavior
The final slash should be preserved when appending a path with the truediv operator.
This would be in accord with the Principle of Least Surprise.
Logs/tracebacks
Python Version
multidict Version
yarl Version
OS
$ uname -a
Linux mattswxp 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: