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

Proper encoding and decoding of source URLs - Fixes special characters in source URL issue #13275

Merged
merged 15 commits into from
Aug 31, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ async def start_copy_from_url(self, source_url, metadata=None, incremental_copy=
:caption: Copy a blob from a URL.
"""
options = self._start_copy_from_url_options(
source_url,
source_url=self._encode_source_url(source_url),
tasherif-msft marked this conversation as resolved.
Show resolved Hide resolved
metadata=metadata,
incremental_copy=incremental_copy,
**kwargs)
Expand Down Expand Up @@ -1163,7 +1163,7 @@ async def stage_block_from_url(
"""
options = self._stage_block_from_url_options(
block_id,
source_url,
source_url=self._encode_source_url(source_url),
source_offset=source_offset,
source_length=source_length,
source_content_md5=source_content_md5,
Expand Down Expand Up @@ -1738,7 +1738,7 @@ async def upload_pages_from_url(self, source_url, # type: str
"""

options = self._upload_pages_from_url_options(
source_url=source_url,
source_url=self._encode_source_url(source_url),
offset=offset,
length=length,
source_offset=source_offset,
Expand Down Expand Up @@ -1979,7 +1979,7 @@ async def append_block_from_url(self, copy_source_url, # type: str
The timeout parameter is expressed in seconds.
"""
options = self._append_block_from_url_options(
copy_source_url,
copy_source_url=self._encode_source_url(copy_source_url),
source_offset=source_offset,
source_length=source_length,
**kwargs
Expand Down
21 changes: 17 additions & 4 deletions sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ def _format_url(self, hostname):
quote(self.blob_name, safe='~/'),
self._query_str)

def _encode_source_url(self, source_url):
parsed_source_url = urlparse(source_url)
source_scheme = parsed_source_url.scheme
source_hostname = parsed_source_url.netloc.rstrip('/')
source_path = unquote(parsed_source_url.path)
source_query = parsed_source_url.query
return "{}://{}{}?{}".format(
source_scheme,
source_hostname,
quote(source_path, safe='~/'),
source_query
)

@classmethod
def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs):
# type: (str, Optional[Any], Optional[Union[str, Dict[str, Any]]], Any) -> BlobClient
Expand Down Expand Up @@ -1705,7 +1718,7 @@ def start_copy_from_url(self, source_url, metadata=None, incremental_copy=False,
:caption: Copy a blob from a URL.
"""
options = self._start_copy_from_url_options(
source_url,
source_url=self._encode_source_url(source_url),
metadata=metadata,
incremental_copy=incremental_copy,
**kwargs)
Expand Down Expand Up @@ -2069,7 +2082,7 @@ def stage_block_from_url(
"""
options = self._stage_block_from_url_options(
block_id,
source_url,
source_url=self._encode_source_url(source_url),
source_offset=source_offset,
source_length=source_length,
source_content_md5=source_content_md5,
Expand Down Expand Up @@ -3045,7 +3058,7 @@ def upload_pages_from_url(self, source_url, # type: str
The timeout parameter is expressed in seconds.
"""
options = self._upload_pages_from_url_options(
source_url=source_url,
source_url=self._encode_source_url(source_url),
offset=offset,
length=length,
source_offset=source_offset,
Expand Down Expand Up @@ -3456,7 +3469,7 @@ def append_block_from_url(self, copy_source_url, # type: str
The timeout parameter is expressed in seconds.
"""
options = self._append_block_from_url_options(
copy_source_url,
copy_source_url=self._encode_source_url(copy_source_url),
source_offset=source_offset,
source_length=source_length,
**kwargs
Expand Down

Large diffs are not rendered by default.

Loading