Skip to content
Merged
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: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ jobs:
linux-tests:
strategy:
matrix:
# TODO: remove older node versions
node: [10, 12, 14, 16, 18, 20, 22]
node: [20, 22]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many joules of energy saved by dropping node 10 - 18? 🔥

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many

fail-fast: false
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 2.0.0
* Path parameter special characters are encoded by default

## 1.8.0
* Make request `body` for HTTP endpoint calls optional [#117](https://github.com/SalesforceCommerceCloud/commerce-sdk-core/pull/117/files)

Expand Down
16 changes: 14 additions & 2 deletions src/base/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ export class Resource {
* @returns Path with actual parameters
*/
substitutePathParameters(path = "", parameters: PathParameters = {}): string {
const encodedPathParams: PathParameters = {};

Object.keys(parameters || {}).forEach((key) => {
const value = parameters?.[key];
if (value) {
encodedPathParams[key] = encodeURIComponent(value);
}
});

return path.replace(/\{([^}]+)\}/g, (_entireMatch, param) => {
if (parameters.hasOwnProperty(param) && parameters[param] !== undefined) {
return parameters[param];
if (
encodedPathParams.hasOwnProperty(param) &&
encodedPathParams[param] !== undefined
) {
return encodedPathParams[param];
}
throw new Error(
`Failed to find a value for required path parameter '${param}'`
Expand Down
4 changes: 1 addition & 3 deletions src/base/staticClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ export async function _delete(options: SdkFetchOptions): Promise<object> {
* @returns Either the Response object or the DTO inside it wrapped in a promise,
* depending upon options.rawResponse
*/
export async function _patch(
options: SdkFetchOptions
): Promise<object> {
export async function _patch(options: SdkFetchOptions): Promise<object> {
return runFetch("patch", options);
}

Expand Down
9 changes: 9 additions & 0 deletions test/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,13 @@ describe("Resource class tests", () => {
// URI decoded: baseUri/path?expand=availability,images&refine=price=(0..150)&refine=c_refinementColor=Red
);
});

it("returns correct url with path param with special characters", () => {
assert.strictEqual(
new Resource("https://example.com", {}, "/path/with/{special}/chars", {
special: "test!@#$%",
}).toString(),
"https://example.com/path/with/test!%40%23%24%25/chars"
);
});
});