Skip to content

Commit 6d4c586

Browse files
committed
[File][Bug]Fix Generate File Url API
Currently when the sas token starts with '?' there will be two '?' in the file url. This commit is to fix the bug.
1 parent 2b50f5c commit 6d4c586

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

azure-storage-file/azure/storage/file/fileservice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def make_file_url(self, share_name, directory_name, file_name,
230230
)
231231

232232
if sas_token:
233-
url += '?' + sas_token
233+
url += (sas_token if sas_token.startswith('?') else '?' + sas_token)
234234

235235
return url
236236

tests/file/test_file.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def test_make_file_url_with_protocol(self):
172172
self.assertEqual(res, 'http://' + self.settings.STORAGE_ACCOUNT_NAME
173173
+ '.file.core.windows.net/vhds/vhd_dir/my.vhd')
174174

175-
@record
176175
def test_make_file_url_with_sas(self):
177176
# Arrange
178177

@@ -184,6 +183,17 @@ def test_make_file_url_with_sas(self):
184183
self.assertEqual(res, 'https://' + self.settings.STORAGE_ACCOUNT_NAME +
185184
'.file.core.windows.net/vhds/vhd_dir/my.vhd?sas')
186185

186+
def test_make_file_url_with_sas_starts_with_question_mark(self):
187+
# Arrange
188+
189+
# Act
190+
res = self.fs.make_file_url(
191+
'vhds', 'vhd_dir', 'my.vhd', sas_token='?sas')
192+
193+
# Assert
194+
self.assertEqual(res, 'https://' + self.settings.STORAGE_ACCOUNT_NAME +
195+
'.file.core.windows.net/vhds/vhd_dir/my.vhd?sas')
196+
187197
@record
188198
def test_create_file(self):
189199
# Arrange

0 commit comments

Comments
 (0)