Skip to content

Unquote URL before quoting it (for backward compatibility) #960

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

Merged
merged 2 commits into from
May 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions office365/sharepoint/files/file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from typing import TYPE_CHECKING, AnyStr
from urllib.parse import quote
from urllib.parse import quote, unquote

import requests

Expand Down Expand Up @@ -608,9 +608,13 @@ def save_binary(context, server_relative_url, content):
:type server_relative_url: str
:type content: str
"""
try:
decoded_server_relative_url = unquote(server_relative_url)
except (ValueError, AttributeError, TypeError):
decoded_server_relative_url = server_relative_url
url = quote(
r"{0}/web/getFileByServerRelativePath(DecodedUrl='{1}')/\$value".format(
context.service_root_url(), server_relative_url
context.service_root_url(), decoded_server_relative_url
),
safe=":/",
)
Expand All @@ -630,9 +634,13 @@ def open_binary(context, server_relative_url):
:type server_relative_url: str
:return Response
"""
try:
decoded_server_relative_url = unquote(server_relative_url)
except (ValueError, AttributeError, TypeError):
decoded_server_relative_url = server_relative_url
url = quote(
r"{0}/web/getFileByServerRelativePath(DecodedUrl='{1}')/\$value".format(
context.service_root_url(), server_relative_url
context.service_root_url(), decoded_server_relative_url
),
safe=":/",
)
Expand Down
Loading