fix: escape the label slug to prevent url errors

This commit is contained in:
shuai
2023-11-13 17:49:05 +08:00
parent 1975d0e46a
commit 21697044f8
8 changed files with 11 additions and 14 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ const Header: FC = () => {
const tagMatch = useMatch('/tags/:slugName');
let askUrl = '/questions/ask';
if (tagMatch && tagMatch.params.slugName) {
askUrl = `${askUrl}?tags=${tagMatch.params.slugName}`;
askUrl = `${askUrl}?tags=${encodeURIComponent(tagMatch.params.slugName)}`;
}
useEffect(() => {
-5
View File
@@ -48,9 +48,7 @@ const Index: FC<Props> = ({
const pluginSlice: Plugin[] = [];
const plugins = PluginKit.getPlugins().filter((plugin) => plugin.activated);
console.log('default list', plugins);
plugins.forEach((plugin) => {
console.log('plugininfo ====', plugin);
if (type && slug_name) {
if (plugin.info.slug_name === slug_name && plugin.info.type === type) {
pluginSlice.push(plugin);
@@ -78,7 +76,6 @@ const Index: FC<Props> = ({
}
if (type === 'editor') {
console.log('444');
const nodes = React.Children.map(children, (child, index) => {
if (index === 15) {
return (
@@ -86,7 +83,6 @@ const Index: FC<Props> = ({
{child}
{pluginSlice.map((ps) => {
const PluginFC = ps.component;
console.log('333', ps.info.slug_name);
return (
// @ts-ignore
<PluginFC key={ps.info.slug_name} {...props} />
@@ -98,7 +94,6 @@ const Index: FC<Props> = ({
}
return child;
});
console.log('222', nodes?.length);
return <div className={className}>{nodes}</div>;
}
@@ -57,7 +57,6 @@ const Index: FC<Props> = ({
},
};
if (typeof onChange === 'function') {
console.log('fieldName', fieldName, enumValues);
onChange(state);
}
};
+1 -1
View File
@@ -38,7 +38,7 @@ const Index: FC<IProps> = ({
className = '',
textClassName = '',
}) => {
href ||= pathFactory.tagLanding(data?.slug_name);
href ||= pathFactory.tagLanding(encodeURIComponent(data.slug_name));
return (
<Link
+1 -1
View File
@@ -115,7 +115,7 @@ const Index = () => {
};
createTag(params)
.then((res) => {
navigate(`/tags/${res.slug_name}/info`, {
navigate(`/tags/${encodeURIComponent(res.slug_name)}/info`, {
replace: true,
});
})
+1 -1
View File
@@ -162,7 +162,7 @@ const Index = () => {
edit_summary: formData.editSummary.value,
};
modifyTag(params).then((res) => {
navigate(`/tags/${formData.slugName.value}/info`, {
navigate(`/tags/${encodeURIComponent(formData.slugName.value)}/info`, {
replace: true,
state: { isReview: res.wait_for_review },
});
+5 -2
View File
@@ -86,8 +86,9 @@ const Index: FC = () => {
if (timelineData?.object_info.object_type === 'tag') {
linkUrl = `/tags/${
timelineData?.object_info.main_tag_slug_name ||
timelineData?.object_info.title
timelineData?.object_info.main_tag_slug_name
? encodeURIComponent(timelineData?.object_info.main_tag_slug_name)
: encodeURIComponent(timelineData?.object_info.title)
}`;
pageTitle = `${t('title_for_tag')} '${timelineData?.object_info.title}'`;
}
@@ -97,6 +98,8 @@ const Index: FC = () => {
usePageTags({
title: pageTitle,
});
console.log('timelineData', linkUrl);
return (
<div className="py-4 mb-5">
<h5 className="mb-4">
+2 -2
View File
@@ -20,12 +20,12 @@
import { seoSettingStore } from '@/stores';
const tagLanding = (slugName: string) => {
const r = slugName ? `/tags/${slugName}` : '/tags';
const r = slugName ? `/tags/${encodeURIComponent(slugName)}` : '/tags';
return r;
};
const tagInfo = (slugName: string) => {
const r = slugName ? `/tags/${slugName}/info` : '/tags';
const r = slugName ? `/tags/${encodeURIComponent(slugName)}/info` : '/tags';
return r;
};