Skip to content

Commit

Permalink
Clean session param in server-side term prop
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Nov 20, 2021
1 parent 17686cd commit 96edcb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export function getOriginHost(origin: string) {
}
}

export function cleanSessionParam(url: string) {
try {
const newUrl = new URL(url);
newUrl.searchParams.delete('giscus');
return newUrl.toString();
} catch (err) {
return url;
}
}

export function isEmpty(v: unknown) {
return v === null || v === undefined || v === '' || Number.isNaN(v);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { assertOrigin } from '../lib/config';
import { ConfigContext, ThemeContext } from '../lib/context';
import { decodeState } from '../lib/oauth/state';
import { ISetConfigMessage } from '../lib/types/giscus';
import { getOriginHost } from '../lib/utils';
import { cleanSessionParam, getOriginHost } from '../lib/utils';
import { env, Theme } from '../lib/variables';
import { getAppAccessToken } from '../services/github/getAppAccessToken';
import { getRepoConfig } from '../services/github/getConfig';
Expand All @@ -17,7 +17,7 @@ import Router from 'next/router';
export async function getServerSideProps({ query, res }: GetServerSidePropsContext) {
const session = (query.session as string) || '';
const repo = (query.repo as string) || '';
const term = (query.term as string) || '';
const term = cleanSessionParam((query.term as string) || '');
const category = (query.category as string) || '';
const number = +query.number || 0;
const repoId = (query.repoId as string) || '';
Expand Down

1 comment on commit 96edcb4

@vercel
Copy link

@vercel vercel bot commented on 96edcb4 Nov 20, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.