Skip to content

Commit b8afd33

Browse files
authored
[storage]Fix issue of not be able to parse URL with account name in Path correctly (Azure#22895)
* Fix issue of not be able to parse URL with account name in Path correctly * Resolve comments
1 parent 68c9acb commit b8afd33

File tree

12 files changed

+139
-11
lines changed

12 files changed

+139
-11
lines changed

sdk/storage/storage-blob/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bugs Fixed
1010

1111
- Fixed a hang issue in BlobClient.downloadToBuffer when encountering transient network failure.
12+
- Refined URL parsing method to let it be able to correctly parse URLs with account name in path.
1213

1314
## 12.11.0 (2022-07-08)
1415

sdk/storage/storage-blob/src/utils/constants.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,28 @@ export const StorageBlobLoggingAllowedQueryParameters = [
210210
export const BlobUsesCustomerSpecifiedEncryptionMsg = "BlobUsesCustomerSpecifiedEncryption";
211211
export const BlobDoesNotUseCustomerSpecifiedEncryption =
212212
"BlobDoesNotUseCustomerSpecifiedEncryption";
213+
214+
/// List of ports used for path style addressing.
215+
/// Path style addressing means that storage account is put in URI's Path segment in instead of in host.
216+
export const PathStylePorts = [
217+
"10000",
218+
"10001",
219+
"10002",
220+
"10003",
221+
"10004",
222+
"10100",
223+
"10101",
224+
"10102",
225+
"10103",
226+
"10104",
227+
"11000",
228+
"11001",
229+
"11002",
230+
"11003",
231+
"11004",
232+
"11100",
233+
"11101",
234+
"11102",
235+
"11103",
236+
"11104",
237+
];

sdk/storage/storage-blob/src/utils/utils.common.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ import {
3232
ClearRange,
3333
BlobPropertiesInternal,
3434
} from "../generated/src/models";
35-
import { DevelopmentConnectionString, HeaderConstants, URLConstants } from "./constants";
35+
import {
36+
DevelopmentConnectionString,
37+
HeaderConstants,
38+
PathStylePorts,
39+
URLConstants,
40+
} from "./constants";
3641
import {
3742
Tags,
3843
ObjectReplicationPolicy,
@@ -603,8 +608,11 @@ export function isIpEndpointStyle(parsedUrl: URLBuilder): boolean {
603608
// Case 2: localhost(:port), use broad regex to match port part.
604609
// Case 3: Ipv4, use broad regex which just check if host contains Ipv4.
605610
// For valid host please refer to https://man7.org/linux/man-pages/man7/hostname.7.html.
606-
return /^.*:.*:.*$|^localhost(:[0-9]+)?$|^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}(:[0-9]+)?$/.test(
607-
host
611+
return (
612+
/^.*:.*:.*$|^localhost(:[0-9]+)?$|^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}(:[0-9]+)?$/.test(
613+
host
614+
) ||
615+
(parsedUrl.getPort() !== undefined && PathStylePorts.includes(parsedUrl.getPort()!))
608616
);
609617
}
610618

sdk/storage/storage-file-datalake/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Bugs Fixed
1313

1414
- Correted permission string parsing in DataLakePathClient.setPermissions() and DataLakePathClient.getAccessControl().
15+
- Refined URL parsing method to let it be able to correctly parse URLs with account name in path.
1516

1617
## 12.10.0 (2022-07-08)
1718

sdk/storage/storage-file-datalake/src/utils/constants.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,28 @@ export const PathResultTypeConstants = {
229229
FileResourceType: "file",
230230
DirectoryResourceType: "directory",
231231
};
232+
233+
/// List of ports used for path style addressing.
234+
/// Path style addressing means that storage account is put in URI's Path segment in instead of in host.
235+
export const PathStylePorts = [
236+
"10000",
237+
"10001",
238+
"10002",
239+
"10003",
240+
"10004",
241+
"10100",
242+
"10101",
243+
"10102",
244+
"10103",
245+
"10104",
246+
"11000",
247+
"11001",
248+
"11002",
249+
"11003",
250+
"11004",
251+
"11100",
252+
"11101",
253+
"11102",
254+
"11103",
255+
"11104",
256+
];

sdk/storage/storage-file-datalake/src/utils/utils.common.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
DevelopmentConnectionString,
1010
EncryptionAlgorithmAES25,
1111
HeaderConstants,
12+
PathStylePorts,
1213
UrlConstants,
1314
} from "./constants";
1415

@@ -571,8 +572,11 @@ export function isIpEndpointStyle(parsedUrl: URLBuilder): boolean {
571572
// Case 2: localhost(:port), use broad regex to match port part.
572573
// Case 3: Ipv4, use broad regex which just check if host contains Ipv4.
573574
// For valid host please refer to https://man7.org/linux/man-pages/man7/hostname.7.html.
574-
return /^.*:.*:.*$|^localhost(:[0-9]+)?$|^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}(:[0-9]+)?$/.test(
575-
host
575+
return (
576+
/^.*:.*:.*$|^localhost(:[0-9]+)?$|^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}(:[0-9]+)?$/.test(
577+
host
578+
) ||
579+
(parsedUrl.getPort() !== undefined && PathStylePorts.includes(parsedUrl.getPort()!))
576580
);
577581
}
578582

sdk/storage/storage-file-share/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bugs Fixed
1010

1111
- Fixed a hang issue in ShareFileClient.downloadToBuffer when encountering transient network failure.
12+
- Refined URL parsing method to let it be able to correctly parse URLs with account name in path.
1213

1314
### Other Changes
1415

sdk/storage/storage-file-share/src/utils/constants.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,28 @@ export const StorageFileLoggingAllowedQueryParameters = [
136136
"copyid",
137137
"restype",
138138
];
139+
140+
/// List of ports used for path style addressing.
141+
/// Path style addressing means that storage account is put in URI's Path segment in instead of in host.
142+
export const PathStylePorts = [
143+
"10000",
144+
"10001",
145+
"10002",
146+
"10003",
147+
"10004",
148+
"10100",
149+
"10101",
150+
"10102",
151+
"10103",
152+
"10104",
153+
"11000",
154+
"11001",
155+
"11002",
156+
"11003",
157+
"11004",
158+
"11100",
159+
"11101",
160+
"11102",
161+
"11103",
162+
"11104",
163+
];

sdk/storage/storage-file-share/src/utils/utils.common.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { AbortSignalLike } from "@azure/abort-controller";
55
import { HttpHeaders, isNode, URLBuilder } from "@azure/core-http";
66
import { HttpAuthorization } from "../models";
7-
import { HeaderConstants, URLConstants } from "./constants";
7+
import { HeaderConstants, PathStylePorts, URLConstants } from "./constants";
88

99
/**
1010
* Reserved URL characters must be properly escaped for Storage services like Blob or File.
@@ -442,8 +442,11 @@ export function isIpEndpointStyle(parsedUrl: URLBuilder): boolean {
442442
// Case 2: localhost(:port), use broad regex to match port part.
443443
// Case 3: Ipv4, use broad regex which just check if host contains Ipv4.
444444
// For valid host please refer to https://man7.org/linux/man-pages/man7/hostname.7.html.
445-
return /^.*:.*:.*$|^localhost(:[0-9]+)?$|^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}(:[0-9]+)?$/.test(
446-
host
445+
return (
446+
/^.*:.*:.*$|^localhost(:[0-9]+)?$|^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])){3}(:[0-9]+)?$/.test(
447+
host
448+
) ||
449+
(parsedUrl.getPort() !== undefined && PathStylePorts.includes(parsedUrl.getPort()!))
447450
);
448451
}
449452

sdk/storage/storage-queue/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Refined URL parsing method to let it be able to correctly parse URLs with account name in path.
12+
1113
### Other Changes
1214

1315
## 12.10.0 (2022-07-08)

0 commit comments

Comments
 (0)