Merge branch 'ui-v0.3' into 'test'

fix: abstract escape character handling

See merge request opensource/answer!221
This commit is contained in:
Li Shuailing 2022-11-10 08:44:33 +00:00
commit f0a0f5b7f0
7 changed files with 32 additions and 12 deletions

View File

@ -35,12 +35,12 @@ module.exports = {
const config = configFunction(proxy, allowedHost); const config = configFunction(proxy, allowedHost);
config.proxy = { config.proxy = {
"/answer": { "/answer": {
target: "http://10.0.20.88:8080/", target: "http://10.0.10.98:2060",
changeOrigin: true, changeOrigin: true,
secure: false secure: false
}, },
"/installation": { "/installation": {
target: "http://10.0.20.88:8080/", target: "http://10.0.10.98:2060",
changeOrigin: true, changeOrigin: true,
secure: false secure: false
} }

View File

@ -16,6 +16,7 @@ import { ADMIN_LIST_STATUS } from '@/common/constants';
import { useEditStatusModal } from '@/hooks'; import { useEditStatusModal } from '@/hooks';
import * as Type from '@/common/interface'; import * as Type from '@/common/interface';
import { useAnswerSearch, changeAnswerStatus } from '@/services'; import { useAnswerSearch, changeAnswerStatus } from '@/services';
import { escapeRemove } from '@/utils';
import '../index.scss'; import '../index.scss';
@ -140,12 +141,10 @@ const Answers: FC = () => {
)} )}
</Stack> </Stack>
<div <div
dangerouslySetInnerHTML={{ className="text-truncate-2 fs-14"
__html: li.description, style={{ maxWidth: '30rem' }}>
}} {escapeRemove(li.description)}
className="last-p text-truncate-2 fs-14" </div>
style={{ maxWidth: '30rem' }}
/>
</Stack> </Stack>
</td> </td>
<td>{li.vote_count}</td> <td>{li.vote_count}</td>

View File

@ -13,6 +13,7 @@ import {
import { useReportModal } from '@/hooks'; import { useReportModal } from '@/hooks';
import * as Type from '@/common/interface'; import * as Type from '@/common/interface';
import { useFlagSearch } from '@/services'; import { useFlagSearch } from '@/services';
import { escapeRemove } from '@/utils';
import '../index.scss'; import '../index.scss';
@ -107,7 +108,7 @@ const Flags: FC = () => {
{li.title} {li.title}
</a> </a>
<small className="text-break text-wrap word"> <small className="text-break text-wrap word">
{li.excerpt} {escapeRemove(li.excerpt)}
</small> </small>
</Stack> </Stack>
</td> </td>

View File

@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
import { following } from '@/services'; import { following } from '@/services';
import { tryNormalLogged } from '@/utils/guard'; import { tryNormalLogged } from '@/utils/guard';
import { escapeRemove } from '@/utils';
interface Props { interface Props {
data; data;
@ -51,7 +52,7 @@ const Index: FC<Props> = ({ data }) => {
<> <>
{data.excerpt && ( {data.excerpt && (
<p className="text-break"> <p className="text-break">
{data.excerpt} {escapeRemove(data.excerpt)}
<Link to={`/tags/${data.slug_name}/info`}> [{t('more')}]</Link> <Link to={`/tags/${data.slug_name}/info`}> [{t('more')}]</Link>
</p> </p>
)} )}

View File

@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import { Icon, Tag, FormatTime, BaseUserCard } from '@/components'; import { Icon, Tag, FormatTime, BaseUserCard } from '@/components';
import type { SearchResItem } from '@/common/interface'; import type { SearchResItem } from '@/common/interface';
import { escapeRemove } from '@/utils';
interface Props { interface Props {
data: SearchResItem; data: SearchResItem;
@ -61,7 +62,7 @@ const Index: FC<Props> = ({ data }) => {
{data.object?.excerpt && ( {data.object?.excerpt && (
<p className="fs-14 text-truncate-2 mb-2 last-p text-break"> <p className="fs-14 text-truncate-2 mb-2 last-p text-break">
{data.object.excerpt} {escapeRemove(data.object.excerpt)}
</p> </p>
)} )}

View File

@ -8,6 +8,7 @@ import { PageTitle, FollowingTags } from '@/components';
import { useTagInfo, useFollow } from '@/services'; import { useTagInfo, useFollow } from '@/services';
import QuestionList from '@/components/QuestionList'; import QuestionList from '@/components/QuestionList';
import HotQuestions from '@/components/HotQuestions'; import HotQuestions from '@/components/HotQuestions';
import { escapeRemove } from '@/utils';
const Questions: FC = () => { const Questions: FC = () => {
const { t } = useTranslation('translation', { keyPrefix: 'tags' }); const { t } = useTranslation('translation', { keyPrefix: 'tags' });
@ -69,7 +70,7 @@ const Questions: FC = () => {
</h3> </h3>
<p className="text-break"> <p className="text-break">
{tagInfo.excerpt || t('no_description')} {escapeRemove(tagInfo.excerpt) || t('no_description')}
<Link to={`/tags/${curTagName}/info`}> [{t('more')}]</Link> <Link to={`/tags/${curTagName}/info`}> [{t('more')}]</Link>
</p> </p>

View File

@ -86,6 +86,22 @@ function formatUptime(value) {
return `< 1 ${t('dates.hour')}`; return `< 1 ${t('dates.hour')}`;
} }
function escapeRemove(str) {
if (!str || typeof str !== 'string') return str;
const arrEntities = {
lt: '<',
gt: '>',
nbsp: ' ',
amp: '&',
quot: '"',
'#39': "'",
};
return str.replace(/&(lt|gt|nbsp|amp|quot|#39);/gi, function (all, t) {
return arrEntities[t];
});
}
export { export {
getQueryString, getQueryString,
thousandthDivision, thousandthDivision,
@ -94,4 +110,5 @@ export {
matchedUsers, matchedUsers,
parseUserInfo, parseUserInfo,
formatUptime, formatUptime,
escapeRemove,
}; };