mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-19 04:00:56 -04:00
feat(client): warn endpoint url submission (#49560)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -596,7 +596,8 @@
|
||||
"editor-url": "Remember to submit the Live App URL.",
|
||||
"http-url": "An unsecure (http) URL cannot be used.",
|
||||
"own-work-url": "Remember to submit your own work.",
|
||||
"publicly-visible-url": "Remember to submit a publicly visible app URL."
|
||||
"publicly-visible-url": "Remember to submit a publicly visible app URL.",
|
||||
"path-url": "You probably want to submit the root path i.e. https://example.com, not https://example.com/path"
|
||||
},
|
||||
"certification": {
|
||||
"executive": "Executive Director, freeCodeCamp.org",
|
||||
|
||||
@@ -15,7 +15,8 @@ import {
|
||||
localhostValidator,
|
||||
composeValidators,
|
||||
fCCValidator,
|
||||
httpValidator
|
||||
httpValidator,
|
||||
pathValidator
|
||||
} from './form-validators';
|
||||
|
||||
export type FormOptions = {
|
||||
@@ -62,7 +63,8 @@ function FormFields(props: FormFieldsProps): JSX.Element {
|
||||
name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator,
|
||||
fCCValidator,
|
||||
httpValidator,
|
||||
isLocalLinkAllowed ? null : localhostValidator
|
||||
isLocalLinkAllowed ? null : localhostValidator,
|
||||
pathValidator
|
||||
)(value);
|
||||
const message: string = (error ||
|
||||
validationError ||
|
||||
|
||||
@@ -9,6 +9,14 @@ const fCCRegex =
|
||||
const localhostRegex = /localhost:/;
|
||||
const httpRegex = /http(?!s|([^s]+?localhost))/;
|
||||
|
||||
function isPathRoot(urlString: string): boolean {
|
||||
try {
|
||||
return new URL(urlString).pathname !== '/';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const editorValidator = (value: string): React.ReactElement | null =>
|
||||
editorRegex.test(value) ? <Trans>validation.editor-url</Trans> : null;
|
||||
|
||||
@@ -23,6 +31,9 @@ export const localhostValidator = (value: string): React.ReactElement | null =>
|
||||
export const httpValidator = (value: string): React.ReactElement | null =>
|
||||
httpRegex.test(value) ? <Trans>validation.http-url</Trans> : null;
|
||||
|
||||
export const pathValidator = (value: string): React.ReactElement | null =>
|
||||
isPathRoot(value) ? <Trans>validation.path-url</Trans> : null;
|
||||
|
||||
type Validator = (value: string) => React.ReactElement | null;
|
||||
export function composeValidators(...validators: (Validator | null)[]) {
|
||||
return (value: string): ReturnType<Validator> | null =>
|
||||
|
||||
Reference in New Issue
Block a user