-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[newcomers-form] fix: accept Google Drive links in profile picture validation #7041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
d6d3ef2
0bc92e9
a4dcc18
6a3ff67
61cd707
aba1488
c25cc46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,10 +27,22 @@ const validatePictureUrl = (value) => { | |||||
| } else { | ||||||
| try { | ||||||
| new URL(value); | ||||||
| const allowedImageExtensions = ["jpg", "jpeg", "png", "webp", "svg", "gif"]; | ||||||
| const extension = value.split(".").pop().toLowerCase(); | ||||||
| if (!allowedImageExtensions.includes(extension)) { | ||||||
| error = "URL must point to an image file (jpg, jpeg, png, svg, webp or gif)."; | ||||||
|
|
||||||
| const isGoogleDrive = value.includes("drive.google.com"); | ||||||
| if (isGoogleDrive) { | ||||||
| const isFileLink = value.includes("/file/d/"); | ||||||
| const isViewLink = value.includes("/view"); | ||||||
| const isDownloadLink = value.includes("/uc?"); | ||||||
|
|
||||||
| if (!isFileLink || (!isViewLink && !isDownloadLink)) { | ||||||
| error = "Please provide a direct Google Drive file link."; | ||||||
| } | ||||||
| } else { | ||||||
| const allowedImageExtensions = ["jpg", "jpeg", "png", "webp", "svg", "gif"]; | ||||||
| const extension = value.split(".").pop().toLowerCase(); | ||||||
| if (!allowedImageExtensions.includes(extension)) { | ||||||
| error = "URL must point to an image file (jpg, jpeg, png, svg, webp or gif)."; | ||||||
| } | ||||||
| } | ||||||
| } catch (_) { | ||||||
| error = "Please enter a URL to an image file."; | ||||||
|
|
@@ -184,7 +196,7 @@ const WebBasedForm = () => { | |||||
| <label htmlFor="picture" className="form-name">Picture</label> | ||||||
| <Field type="url" className="text-field" id="picture" name="picture" validate={validatePictureUrl}/> | ||||||
| {errors.picture && touched.picture && <div style={{ margin: "0px", color: "red", fontSize: "16px" }}>{errors.picture}</div>} | ||||||
| <p className="para label">Please provide a link to your profile photo. Profile photos are used for <Link to="/community/members">community member profiles</Link> of longstanding community members.</p> | ||||||
| <p className="para label">Please provide a link to your profile photo. Profile photos are used for <Link to="/community/members">community member profiles</Link> of longstanding community members. For Google Drive links, please ensure you're using direct image links that end with .jpg, .png, etc.</p> | ||||||
|
||||||
| <p className="para label">Please provide a link to your profile photo. Profile photos are used for <Link to="/community/members">community member profiles</Link> of longstanding community members. For Google Drive links, please ensure you're using direct image links that end with .jpg, .png, etc.</p> | |
| <p className="para label">Please provide a link to your profile photo. Profile photos are used for <Link to="/community/members">community member profiles</Link> of longstanding community members. For Google Drive links, please ensure you're using a direct image link that is accessible to anyone with the link.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic is incorrect. It requires BOTH
/file/d/AND either/viewOR/uc?to be present, but Google Drive file links typically have the formatdrive.google.com/file/d/{ID}/viewwhere/viewand/uc?don't appear together. The condition!isFileLink || (!isViewLink && !isDownloadLink)will reject valid links likedrive.google.com/file/d/abc123/view. Change toif (!isFileLink || !(isViewLink || isDownloadLink)).