shuashuai commented on PR #970:
URL: https://github.com/apache/incubator-answer/pull/970#issuecomment-2144850785

   > Initially, I also thought it was a front-end issue, because the 
encodeURIComponent function was used, so I deleted `encodeURICompontent` in the 
functions related to the tag `slugName`.
   > 
   > For example, in `ui/src/router/pathFactory.ts`
   > 
   > ```
   > const tagLanding = (slugName: string) => {
   >   const r = slugName ? `/tags/${encodeURIComponent(slugName)}` : '/tags';
   >   return r;
   > };
   > ```
   > 
   > Also in `ui/src/components/Tag/index.tsx`
   > 
   > ```
   > const Index: FC<IProps> = ({
   >   ...
   >   href ||= pathFactory.tagLanding(encodeURIComponent(data.slug_name));
   >   ...
   > })
   > ```
   > 
   > This will lead to new issues; if the slugName contains '/' or some special 
characters, it will result in URI errors.
   > 
   > Thus, I decided to resolve this issue using a method similar to the one 
used for handling `UrlTitle`.
   > 
   > I'm not sure if my understanding is correct, and I would be happy to 
discuss this issue with you.
   
   Tags are different from titles. tags are created without any checksums, so 
in order to prevent special characters from damaging the integrity of the URL, 
`encodeURIComponent` is used here to escape.
   
   this was done with the following main considerations in mind:
   
   1. make the display of the tag on the page look the same as when it was 
created.
   2. no need to consider the compatibility of some of its old data.
   
   like this:
   
![image](https://github.com/apache/incubator-answer/assets/30591202/be34ae62-e0e8-425a-ac0e-bc6ba5e795e6)
   
![image](https://github.com/apache/incubator-answer/assets/30591202/beeba798-c519-481f-8b66-322a27eb00e8)
   
   The reason for using the `encodeURIComponent` method is to ensure that the 
URL conforms to the requirements, and there is no such restriction in the API, 
so we just need to restore the escaped parameters in the API inputs.
   
   The APIs involved are
   
   1. `/answer/api/v1/tag?name=xxxx`
   2. `/answer/api/v1/question/page?page_size=20&page=1&order=active&tag=xxxx`
   
   If you have other questions, you can continue the discussion.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to