mirror of https://gitee.com/answerdev/answer.git
Merge pull request #380 from answerdev/feat/1.1.0/ui
fix(guard.isIgnoredPath): Avoid incorrect matches when using `indexOf`
This commit is contained in:
commit
9ac3453b91
|
@ -65,12 +65,13 @@ const Index: FC = () => {
|
|||
clearTimeout(checkTimer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (getUaType() !== USER_AGENT_NAMES.WeCom) {
|
||||
return (
|
||||
<Card className="text-center">
|
||||
<Card.Body>
|
||||
<Card.Title as="h3" className="mb-3">
|
||||
{ucAgent?.agent_info.display_name} {t('login')}
|
||||
{ucAgent?.agent_info?.display_name} {t('login')}
|
||||
</Card.Title>
|
||||
{qrcodeDataUrl ? (
|
||||
<>
|
||||
|
@ -82,7 +83,7 @@ const Index: FC = () => {
|
|||
/>
|
||||
<div className="text-secondary mt-3">
|
||||
{t('qrcode_login_tip', {
|
||||
agentName: ucAgent?.agent_info.display_name,
|
||||
agentName: ucAgent?.agent_info?.display_name,
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
|
|
|
@ -13,7 +13,7 @@ const Index = () => {
|
|||
const { t } = useTranslation('translation');
|
||||
const [searchParam] = useSearchParams();
|
||||
const { agent: ucAgent } = userCenterStore();
|
||||
let agentName = ucAgent?.agent_info.name || '';
|
||||
let agentName = ucAgent?.agent_info?.name || '';
|
||||
if (searchParam.get('agent_name')) {
|
||||
agentName = searchParam.get('agent_name') || '';
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ const Index: FC = () => {
|
|||
<Card>
|
||||
<Card.Body>
|
||||
<h3 className="text-center pt-3 mb-3">
|
||||
{ucAgent?.agent_info.display_name} {t('login')}
|
||||
{ucAgent?.agent_info?.display_name} {t('login')}
|
||||
</h3>
|
||||
<p className="text-danger text-center">
|
||||
{t('login_failed_email_tip')}
|
||||
|
|
|
@ -13,7 +13,7 @@ const Index = () => {
|
|||
const { t } = useTranslation('translation');
|
||||
const [searchParam] = useSearchParams();
|
||||
const { agent: ucAgent } = userCenterStore();
|
||||
let agentName = ucAgent?.agent_info.name || '';
|
||||
let agentName = ucAgent?.agent_info?.name || '';
|
||||
if (searchParam.get('agent_name')) {
|
||||
agentName = searchParam.get('agent_name') || '';
|
||||
}
|
||||
|
|
|
@ -10,6 +10,47 @@ const equalToCurrentHref = (target: string, base?: string) => {
|
|||
const targetUrl = new URL(target, base);
|
||||
return targetUrl.toString() === window.location.href;
|
||||
};
|
||||
const matchToCurrentHref = (target: string) => {
|
||||
target = (target || '').trim();
|
||||
// Empty string or `/` can match any path
|
||||
if (!target || target === '/') {
|
||||
return true;
|
||||
}
|
||||
const { pathname, search, hash } = window.location;
|
||||
const tPart = target.split('?');
|
||||
|
||||
/**
|
||||
* With the current requirements, `hash` and `search` can simply be matched
|
||||
* Later extended to field-by-field matching if necessary
|
||||
*/
|
||||
if (tPart[1]) {
|
||||
const tChip = tPart[1].split('#');
|
||||
const tSearch = tChip[0] || '';
|
||||
const tHash = tChip[1] || '';
|
||||
if (tHash && hash.indexOf(tHash) === -1) {
|
||||
return false;
|
||||
}
|
||||
if (tSearch && search.indexOf(tSearch) === -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As determination above, `tPart[0]` must be a valid string
|
||||
*/
|
||||
let pathMatch = true;
|
||||
const tPath = tPart[0].split('/').filter((_) => !!_);
|
||||
const lPath = pathname.split('/').filter((_) => !!_);
|
||||
|
||||
tPath.forEach((p, i) => {
|
||||
const lp = lPath[i];
|
||||
if (p !== lp) {
|
||||
pathMatch = false;
|
||||
}
|
||||
});
|
||||
|
||||
return pathMatch;
|
||||
};
|
||||
|
||||
const storageLoginRedirect = () => {
|
||||
const { pathname } = window.location;
|
||||
|
@ -136,5 +177,6 @@ export const floppyNavigation = {
|
|||
isRoutableLink,
|
||||
handleRouteLinkClick,
|
||||
equalToCurrentHref,
|
||||
matchToCurrentHref,
|
||||
storageLoginRedirect,
|
||||
};
|
||||
|
|
|
@ -94,13 +94,15 @@ export const IGNORE_PATH_LIST = [
|
|||
'/user-center/',
|
||||
];
|
||||
|
||||
export const isIgnoredPath = (ignoredPath: string | string[]) => {
|
||||
export const isIgnoredPath = (ignoredPath?: string | string[]) => {
|
||||
if (!ignoredPath) {
|
||||
ignoredPath = IGNORE_PATH_LIST;
|
||||
}
|
||||
if (!Array.isArray(ignoredPath)) {
|
||||
ignoredPath = [ignoredPath];
|
||||
}
|
||||
const { pathname } = window.location;
|
||||
const matchingPath = ignoredPath.find((_) => {
|
||||
return pathname.indexOf(_) !== -1;
|
||||
const matchingPath = ignoredPath.find((p) => {
|
||||
return floppyNavigation.matchToCurrentHref(p);
|
||||
});
|
||||
return !!matchingPath;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue