Skip to content

Commit 968629d

Browse files
committed
Don't include # when url fragment is empty
1 parent a734a6c commit 968629d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

packages/auth/src/core/util/handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ export async function _getRedirectUrl(
120120
const appCheckTokenFragment = appCheckToken
121121
? `${FIREBASE_APP_CHECK_FRAGMENT_ID}=${encodeURIComponent(appCheckToken)}`
122122
: '';
123+
const fragment = appCheckTokenFragment ? `#${appCheckTokenFragment}` : '';
123124

124125
// Start at index 1 to skip the leading '&' in the query string
125126
return `${getHandlerBase(auth)}?${querystring(paramsDict).slice(
126127
1
127-
)}#${appCheckTokenFragment}`;
128+
)}${fragment}`;
128129
}
129130

130131
function getHandlerBase({ config }: AuthInternal): string {

packages/auth/src/platform_browser/popup_redirect.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ describe('platform_browser/popup_redirect', () => {
150150
await resolver._openPopup(auth, provider, event);
151151

152152
const matches = (popupUrl as string).match(/.*?#(.*)/);
153-
expect(matches).not.to.be.null;
154-
const fragment = matches![1];
155-
expect(fragment).to.be.empty;
153+
// The '#' character will not be included when the url fragment is not attached,
154+
// so the url will not match the pattern
155+
expect(matches).to.be.null;
156156
});
157157

158158
it('does not add the App Check token in the url fragment if controller unavailable', async () => {
@@ -164,9 +164,9 @@ describe('platform_browser/popup_redirect', () => {
164164
await resolver._openPopup(auth, provider, event);
165165

166166
const matches = (popupUrl as string).match(/.*?#(.*)/);
167-
expect(matches).not.to.be.null;
168-
const fragment = matches![1];
169-
expect(fragment).to.be.empty;
167+
// The '#' character will not be included when the url fragment is not attached,
168+
// so the url will not match the pattern
169+
expect(matches).to.be.null;
170170
});
171171

172172
it('throws an error if apiKey is unspecified', async () => {
@@ -259,9 +259,9 @@ describe('platform_browser/popup_redirect', () => {
259259
});
260260

261261
const matches = newWindowLocation.match(/.*?#(.*)/);
262-
expect(matches).not.to.be.null;
263-
const fragment = matches![1];
264-
expect(fragment).to.be.empty;
262+
// The '#' character will not be included when the url fragment is not attached,
263+
// so the url will not match the pattern
264+
expect(matches).to.be.null;
265265
});
266266

267267
it('does not add the App Check token in the url fragment if controller unavailable', async () => {
@@ -279,9 +279,9 @@ describe('platform_browser/popup_redirect', () => {
279279
});
280280

281281
const matches = newWindowLocation.match(/.*?#(.*)/);
282-
expect(matches).not.to.be.null;
283-
const fragment = matches![1];
284-
expect(fragment).to.be.empty;
282+
// The '#' character will not be included when the url fragment is not attached,
283+
// so the url will not match the pattern
284+
expect(matches).to.be.null;
285285
});
286286

287287
it('throws an error if authDomain is unspecified', async () => {

0 commit comments

Comments
 (0)