Closed byerer closed 1 month ago
https://xxxxx/tags/中文
-> https://xxxxx/tags/%25E4%25B8%25AD%25E6%2596%2587
The reason for this issue is as follows. When the frontend jumps, it performs a URL encoding operation on the tag name, and then the frontend directly calls the API using the encoded information. Therefore, the solution may be to decode the tag in the frontend before calling the API. It is possible that the backend does not need to make the modifications for this issue, only the frontend may need to be modified. Let's discuss it together with @shuashuai .
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.
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 tagslugName
.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:
like this:
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
/answer/api/v1/tag?name=xxxx
/answer/api/v1/question/page?page_size=20&page=1&order=active&tag=xxxx
If you have other questions, you can continue the discussion.
961
Adopted the method used for handling UrlTitle to process slugname.