This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch feat/1.2.1/ui
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 21697044f804fd1555836b1969a9c6ba6bb0994c
Author: shuai <[email protected]>
AuthorDate: Mon Nov 13 17:49:05 2023 +0800

    fix: escape the label slug to prevent url errors
---
 ui/src/components/Header/index.tsx                | 2 +-
 ui/src/components/PluginRender/index.tsx          | 5 -----
 ui/src/components/SchemaForm/components/Check.tsx | 1 -
 ui/src/components/Tag/index.tsx                   | 2 +-
 ui/src/pages/Tags/Create/index.tsx                | 2 +-
 ui/src/pages/Tags/Edit/index.tsx                  | 2 +-
 ui/src/pages/Timeline/index.tsx                   | 7 +++++--
 ui/src/router/pathFactory.ts                      | 4 ++--
 8 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/ui/src/components/Header/index.tsx 
b/ui/src/components/Header/index.tsx
index 9b3b1970..68932962 100644
--- a/ui/src/components/Header/index.tsx
+++ b/ui/src/components/Header/index.tsx
@@ -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(() => {
diff --git a/ui/src/components/PluginRender/index.tsx 
b/ui/src/components/PluginRender/index.tsx
index 23aebd28..3da9fd0b 100644
--- a/ui/src/components/PluginRender/index.tsx
+++ b/ui/src/components/PluginRender/index.tsx
@@ -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>;
   }
diff --git a/ui/src/components/SchemaForm/components/Check.tsx 
b/ui/src/components/SchemaForm/components/Check.tsx
index fbb06e9b..3ae1fa4f 100644
--- a/ui/src/components/SchemaForm/components/Check.tsx
+++ b/ui/src/components/SchemaForm/components/Check.tsx
@@ -57,7 +57,6 @@ const Index: FC<Props> = ({
       },
     };
     if (typeof onChange === 'function') {
-      console.log('fieldName', fieldName, enumValues);
       onChange(state);
     }
   };
diff --git a/ui/src/components/Tag/index.tsx b/ui/src/components/Tag/index.tsx
index dc151afe..44a5ae63 100644
--- a/ui/src/components/Tag/index.tsx
+++ b/ui/src/components/Tag/index.tsx
@@ -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
diff --git a/ui/src/pages/Tags/Create/index.tsx 
b/ui/src/pages/Tags/Create/index.tsx
index bf41fd58..485c7cd6 100644
--- a/ui/src/pages/Tags/Create/index.tsx
+++ b/ui/src/pages/Tags/Create/index.tsx
@@ -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,
         });
       })
diff --git a/ui/src/pages/Tags/Edit/index.tsx b/ui/src/pages/Tags/Edit/index.tsx
index 32ce788d..a01e278c 100644
--- a/ui/src/pages/Tags/Edit/index.tsx
+++ b/ui/src/pages/Tags/Edit/index.tsx
@@ -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 },
       });
diff --git a/ui/src/pages/Timeline/index.tsx b/ui/src/pages/Timeline/index.tsx
index cd283616..e20d50ef 100644
--- a/ui/src/pages/Timeline/index.tsx
+++ b/ui/src/pages/Timeline/index.tsx
@@ -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">
diff --git a/ui/src/router/pathFactory.ts b/ui/src/router/pathFactory.ts
index 97d74afb..ec326acf 100644
--- a/ui/src/router/pathFactory.ts
+++ b/ui/src/router/pathFactory.ts
@@ -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;
 };
 

Reply via email to