Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(adminGeneral): restrict site_url only before root path

haitao(lj)9996b5e4e121
diff --git a/ui/src/components/SchemaForm/README.md b/ui/src/components/SchemaForm/README.md
index e9ab80fd..46676a8f 100644
--- a/ui/src/components/SchemaForm/README.md
+++ b/ui/src/components/SchemaForm/README.md
@@ -8,7 +8,7 @@ SchemaForm is a component that can be used to render a form based on a [JSON sch
### Basic Usage
-```jsx
+```tsx
import React from 'react';
import { SchemaForm, initFormData, JSONSchema, UISchema } from '@/components';
@@ -26,7 +26,7 @@ const schema: JSONSchema = {
sex:{
type: 'boolean',
title: 'sex',
- enum: [1, 2]
+ enum: [1, 2],
enumNames: ['male', 'female'],
}
},
diff --git a/ui/src/pages/Admin/General/index.tsx b/ui/src/pages/Admin/General/index.tsx
index 3906f0fe..781a1284 100644
--- a/ui/src/pages/Admin/General/index.tsx
+++ b/ui/src/pages/Admin/General/index.tsx
@@ -6,6 +6,7 @@ import type * as Type from '@/common/interface';
import { useToast } from '@/hooks';
import { siteInfoStore } from '@/stores';
import { useGeneralSetting, updateGeneralSetting } from '@/services';
+import Pattern from '@/common/pattern';
import '../index.scss';
@@ -53,7 +54,20 @@ const General: FC = () => {
'ui:options': {
invalid: t('site_url.validate'),
validator: (value) => {
- if (!/^(https?):\/\/([\w.]+\/?)\S*$/.test(value)) {
+ let url: URL | undefined;
+ try {
+ url = new URL(value);
+ } catch (ex) {
+ // eslint-disable-next-line no-empty
+ }
+ // only can input url with root pathname
+ if (
+ !url ||
+ /^https?:$/.test(url.protocol) === false ||
+ url.pathname !== '/' ||
+ !url.search ||
+ !url.hash
+ ) {
return false;
}
return true;
@@ -64,9 +78,7 @@ const General: FC = () => {
'ui:options': {
invalid: t('contact_email.validate'),
validator: (value) => {
- if (
- !/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value)
- ) {
+ if (Pattern.email.test(value)) {
return false;
}
return true;