feat(client): warn endpoint url submission (#49560)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Shaun Hamilton
2023-03-06 10:54:48 +00:00
committed by GitHub
parent a4ce8fa425
commit f45d8b06dc
3 changed files with 17 additions and 3 deletions

View File

@@ -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",

View File

@@ -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 ||

View File

@@ -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 =>