Skip to content

Commit

Permalink
join extra state params
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Faircloth committed Oct 17, 2023
1 parent b658123 commit 047fb97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/SigninResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,22 @@ describe("SigninResponse", () => {

it("should read url_state", () => {
// act
const subject = new SigninResponse(new URLSearchParams("state=foo%3Bbar"));
const subject = new SigninResponse(new URLSearchParams("state=foo;bar"));

// assert
expect(subject.state).toEqual("foo");
expect(subject.url_state).toEqual("bar");
});

it("should return url_state that uses the delimiter unmodified", () => {
// act
const subject = new SigninResponse(new URLSearchParams("state=foo;bar;baz"));

// assert
expect(subject.state).toEqual("foo");
expect(subject.url_state).toEqual("bar;baz");
});

it("should read code", () => {
// act
const subject = new SigninResponse(new URLSearchParams("code=foo"));
Expand Down
4 changes: 3 additions & 1 deletion src/SigninResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export class SigninResponse {
if (this.state) {
const splitState = decodeURIComponent(this.state).split(URL_STATE_DELIMITER);
this.state = splitState[0];
this.url_state = splitState[1];
if (splitState.length > 1) {
this.url_state = splitState.slice(1).join(URL_STATE_DELIMITER);
}
}

this.error = params.get("error");
Expand Down

0 comments on commit 047fb97

Please sign in to comment.