diff --git a/sdk/core/core-client/CHANGELOG.md b/sdk/core/core-client/CHANGELOG.md index 975830da8577..1a5fb863f7db 100644 --- a/sdk/core/core-client/CHANGELOG.md +++ b/sdk/core/core-client/CHANGELOG.md @@ -7,6 +7,9 @@ - Added a new property endpoint in ServiceClientOptions and mark the baseUri as deprecated to encourage people to use endpoint. See issue link [here](https://github.com/Azure/autorest.typescript/issues/1337) - Upgraded our `@azure/core-tracing` dependency to version 1.0 +### Bugs fixed +- Prevent adding the path twice to a request URL that already has it. + ## 1.5.0 (2022-02-03) ### Features Added diff --git a/sdk/core/core-client/src/urlHelpers.ts b/sdk/core/core-client/src/urlHelpers.ts index 966fe2808869..a9a2b5c2e731 100644 --- a/sdk/core/core-client/src/urlHelpers.ts +++ b/sdk/core/core-client/src/urlHelpers.ts @@ -42,7 +42,8 @@ export function getRequestUrl( if (isAbsoluteUrl(path)) { requestUrl = path; isAbsolutePath = true; - } else { + } else if (!requestUrl.match(path)) { + // If path is already in URL, don't add it twice requestUrl = appendPath(requestUrl, path); } } diff --git a/sdk/core/core-client/test/urlHelpers.spec.ts b/sdk/core/core-client/test/urlHelpers.spec.ts index 3e7af7f1551c..621042d3bf20 100644 --- a/sdk/core/core-client/test/urlHelpers.spec.ts +++ b/sdk/core/core-client/test/urlHelpers.spec.ts @@ -253,4 +253,17 @@ describe("getRequestUrl", function () { "https://management.azure.com/subscriptions/subscription-id/resourceGroups/rg2/providers/Microsoft.Network/virtualNetworks/samplename?api-version=2020-08-01&api-version=2021-08-01&api-version=2022-08-01" ); }); + + it("should not add path twice if path is already in the url", function () { + const operationSpecFixedPath: OperationSpec = { + path: "/deletedSecrets", + httpMethod: "DELETE", + responses: {}, + urlParameters: [], + serializer, + }; + + const result = getRequestUrl("https://test.com/deletedSecrets", operationSpecFixedPath, {}, {}); + assert.strictEqual(result, "https://test.com/deletedSecrets"); + }); });