Skip to content

Commit

Permalink
Fix __next link to be url component decoded (e.g. + needs to be e…
Browse files Browse the repository at this point in the history
…ncoded)
  • Loading branch information
oklemenz2 committed Oct 11, 2024
1 parent e258eda commit acae4a8
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- tbd
- Fix `__next` link to be url component decoded (e.g. `+` needs to be encoded)

## Version 1.13.4 - 2024-10-07

Expand Down
62 changes: 31 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"eslint": "^9.12.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-n": "^17.11.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"supertest": "^7.0.0",
Expand Down
20 changes: 9 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4116,17 +4116,15 @@ function cov2ap(options = {}) {
});
return (
serviceUri(req) +
decodeURIComponent(
URL.format({
...originalUrl,
search: null,
pathname: originalUrl.contextPath,
query: {
...originalUrl.query,
...params,
},
}),
)
URL.format({
...originalUrl,
search: null,
pathname: originalUrl.contextPath,
query: {
...originalUrl.query,
...params,
},
})
);
}

Expand Down
4 changes: 2 additions & 2 deletions test-hana/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ describe("hana-main", () => {
response = await util.callRead(request, "/odata/v2/main/HeaderLimited");
expect(response.statusCode).toEqual(200);
expect(response.body.d.results).toBeDefined();
expect(response.body.d.__next).toMatch(/http:\/\/localhost:(\d*)\/odata\/v2\/main\/HeaderLimited\?\$skiptoken=1/);
expect(response.body.d.__next).toMatch(/http:\/\/localhost:(\d*)\/odata\/v2\/main\/HeaderLimited\?%24skiptoken=1/);
const nextUrl = response.body.d.__next.match(/http:\/\/localhost:\d*(.*)/)[1];
response = await util.callRead(request, nextUrl);
expect(response.body.d.results).toBeDefined();
expect(response.body.d.results).toHaveLength(1);
expect(response.body.d.__next).toMatch(/http:\/\/localhost:(\d*)\/odata\/v2\/main\/HeaderLimited\?\$skiptoken=2/);
expect(response.body.d.__next).toMatch(/http:\/\/localhost:(\d*)\/odata\/v2\/main\/HeaderLimited\?%24skiptoken=2/);
await util.callDelete(request, `/odata/v2/main/Header(guid'${id}')`);
});
});
Expand Down
35 changes: 32 additions & 3 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ describe("main", () => {
expect(response.statusCode).toEqual(200);
expect(response.body.d.results).toBeDefined();
expect(response.body.d.__delta).toMatch(
/http:\/\/localhost:(\d*)\/odata\/v2\/main\/HeaderDelta\(guid'.*?'\)\/Items\?\$filter=name eq 'a \/'&!deltatoken='(\d*)'/,
/http:\/\/localhost:(\d*)\/odata\/v2\/main\/HeaderDelta\(guid'.*?'\)\/Items\?%24filter=name%20eq%20'a%20%2F'&!deltatoken='(\d*)'/,
);
});

Expand All @@ -694,12 +694,41 @@ describe("main", () => {
expect(response.statusCode).toEqual(200);
expect(response.body.d.results).toBeDefined();
expect(response.body.d.results).toHaveLength(1);
expect(response.body.d.__next).toMatch(/http:\/\/localhost:(\d*)\/odata\/v2\/main\/FavoriteLimited\?\$skiptoken=1/);
expect(response.body.d.__next).toMatch(
/http:\/\/localhost:(\d*)\/odata\/v2\/main\/FavoriteLimited\?%24skiptoken=1/,
);
const nextUrl = response.body.d.__next.match(/http:\/\/localhost:\d*(.*)/)[1];
response = await util.callRead(request, nextUrl);
expect(response.body.d.results).toBeDefined();
expect(response.body.d.results).toHaveLength(1);
expect(response.body.d.__next).toMatch(/http:\/\/localhost:(\d*)\/odata\/v2\/main\/FavoriteLimited\?\$skiptoken=2/);
expect(response.body.d.__next).toMatch(
/http:\/\/localhost:(\d*)\/odata\/v2\/main\/FavoriteLimited\?%24skiptoken=2/,
);
});

it("GET request filtered with next link responses", async () => {
let response = await util.callRead(request, "/odata/v2/main/FavoriteLimited?$filter=name eq 'WE%2BDE-SFSNRF'");
expect(response.statusCode).toEqual(200);
expect(response.body.d.results).toBeDefined();
expect(response.body.d.results).toHaveLength(1);
expect(response.body.d.results[0]).toMatchObject({
name: "WE+DE-SFSNRF",
value: "+",
});
expect(response.body.d.__next).toMatch(
/http:\/\/localhost:(\d*)\/odata\/v2\/main\/FavoriteLimited\?%24filter=name%20eq%20'WE%2BDE-SFSNRF'&%24skiptoken=1/,
);
response = await util.callRead(request, "/odata/v2/main/FavoriteLimited?$filter=name eq 'WE+DE-SFSNRF'");
expect(response.statusCode).toEqual(200);
expect(response.body.d.results).toBeDefined();
expect(response.body.d.results).toHaveLength(1);
expect(response.body.d.results[0]).toMatchObject({
name: "WE DE-SFSNRF",
value: " ",
});
expect(response.body.d.__next).toMatch(
/http:\/\/localhost:(\d*)\/odata\/v2\/main\/FavoriteLimited\?%24filter=name%20eq%20'WE%20DE-SFSNRF'&%24skiptoken=1/,
);
});

it("GET request with stream", async () => {
Expand Down

0 comments on commit acae4a8

Please sign in to comment.