Skip to content

Commit 8ee4597

Browse files
authored
[core-client-rest] Set comma as parametrized path delimiter (Azure#24997)
### Packages impacted by this PR @azure-rest/core-client ### Issues associated with this PR Azure#24982 ### Describe the problem that is addressed by this PR Currently core-client-rest fills in parameterized paths assuming that there will be only one parametrized element in a given path part. As surfaced in the linked issue, there are scenarios where a single path part can have more than one parameter. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? Currently we only consider `/` as a delimiter to look for the next path parameter. Adding `,` as a delimiter addresses this issue. ### Are there test cases added in this PR? _(If not, why?)_ Yes ### Provide a list of related PRs _(if any)_ N/A
1 parent 85ac9d2 commit 8ee4597

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sdk/core/core-client-rest/src/urlHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function buildRoutePath(
103103
value = encodeURIComponent(pathParam);
104104
}
105105

106-
routePath = routePath.replace(/{([^/]+)}/, value);
106+
routePath = routePath.replace(/\{\w+\}/, value);
107107
}
108108
return routePath;
109109
}

sdk/core/core-client-rest/test/urlHelpers.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ describe("urlHelpers", () => {
8989
assert.equal(result, `https://example.org/foo?existing=hey&foo=1&bar=two`);
9090
});
9191

92+
it("should build url with parenthesis", () => {
93+
const path = "/certificates(thumbprintAlgorithm={thumbprintAlgorithm},thumbprint={thumbprint})";
94+
const parameters = ["foo", "bar"];
95+
const result = buildRequestUrl(mockBaseUrl, path, parameters);
96+
97+
assert.equal(result, `${mockBaseUrl}/certificates(thumbprintAlgorithm=foo,thumbprint=bar)`);
98+
});
99+
92100
it("should build url with array queries", () => {
93101
const testArray = ["ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", null as any, ""] as string[];
94102
let result = buildRequestUrl(mockBaseUrl, "/foo?existing=hey", [], {

0 commit comments

Comments
 (0)