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

[Core-client] BUG: getRequestUrl method adds the path twice #21595

Closed
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions sdk/core/core-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sdk/core/core-client/src/urlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
13 changes: 13 additions & 0 deletions sdk/core/core-client/test/urlHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});