Skip to content

Commit

Permalink
Fix paths beginning with a double slash
Browse files Browse the repository at this point in the history
CI started failing as there was an unexpected update to fast-check. This version now generates URLs containing '//' as the beginning of the path, which then break's constructing URL objects which consider it to be an invalid protocol relative URL.

Refs #1834, 8f6b150, dubzzz/fast-check#4896
  • Loading branch information
thewilkybarkid committed Aug 28, 2024
1 parent e6c1fb1 commit 3fc0404
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ export const handlePageResponse = ({
match(response.canonical)
.with(P.string, canonical =>
R.asks(
({ publicUrl }: PublicUrlEnv) => new URL(encodeURI(canonical).replace(/^([^/])/, '/$1'), publicUrl).href,
({ publicUrl }: PublicUrlEnv) =>
new URL(`${publicUrl.origin}${encodeURI(canonical).replace(/^([^/])/, '/$1')}`).href,
),
)
.with(undefined, R.of)
Expand Down Expand Up @@ -307,7 +308,7 @@ const handleTwoUpPageResponse = ({
'canonical',
RM.asks(
({ publicUrl }: PublicUrlEnv) =>
new URL(encodeURI(response.canonical).replace(/^([^/])/, '/$1'), publicUrl).href,
new URL(`${publicUrl.origin}${encodeURI(response.canonical).replace(/^([^/])/, '/$1')}`).href,
),
),
RM.bindW(
Expand Down Expand Up @@ -376,7 +377,7 @@ const handleLogInResponse = ({
response: LogInResponse
}): RM.ReaderMiddleware<OrcidOAuthEnv & PublicUrlEnv, StatusOpen, ResponseEnded, never, void> =>
pipe(
RM.asks(({ publicUrl }: PublicUrlEnv) => new URL(response.location, publicUrl).href),
RM.asks(({ publicUrl }: PublicUrlEnv) => new URL(`${publicUrl.origin}${response.location}`).href),
RM.ichainW(requestAuthorizationCode('/authenticate')),
R.local(addRedirectUri()),
)
Expand Down
2 changes: 1 addition & 1 deletion test/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ describe('handleResponse', () => {
response_type: 'code',
redirect_uri: new URL('/orcid', publicUrl).toString(),
scope: '/authenticate',
state: new URL(response.location, publicUrl).href,
state: new URL(`${publicUrl.origin}${response.location}`).href,
}).toString()}`,
orcidOauth.authorizeUrl,
).href,
Expand Down

0 comments on commit 3fc0404

Please sign in to comment.