Skip to content

Weird validation for portfolio inputs in the setting page #49132

Description

@Sboonny

Describe the Issue

Validations are weirdly strict in imageUrl, but can still accept broken result, but lenient on URL section, although it doesn't accept broken URL.

Affected Page

https://www.freecodecamp.org/settings

Steps to Reproduce

  1. Go to https://www.freecodecamp.org/settings
  2. Type "https.com" in URL section
  3. Type "https://github.com/freeCodeCamp/cdn/blob/main/build/chapter/puppy-small.jpg" in the image section
  4. Go to your portfolio
  5. See broken Media component

Note: I know that the correct URL is https://cdn.freecodecamp.org/chapter/orange-graphics-small.jpg, the issue is that I can spend time creating an item in portfolio, and it results in broken image later without knowing why.
image

Expected behavior

  • stricter validation on URL
  • lenient validation on imageURL, maybe shows how image looks instead, so it becomes harder to break it in the portfolio page
    image

Screenshots

image

System

  • Device: [e.g. iPhone 6, Laptop]
  • OS: [e.g. iOS 14, Windows 10, Ubuntu 20.04]
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 22]

Additional context

No response

Activity

  1. added
    status: waiting triage
    platform: learn
    on Jan 25, 2023
  2. ShaunSHamilton commented on Jan 25, 2023

    @ShaunSHamilton
    Member

    I do not see a bug here. The validation does what majority of the WWW uses when validating such an input - is the input a valid URL - does it match the URL spec. We already go a bit overboard with the validation, as I would have simply used the isURL validator, and left the rest.

    The URL validation is done here:

    getUrlValidation(maybeUrl: string, isImage?: boolean) {
    const { t } = this.props;
    const len = maybeUrl.length;
    if (len >= 4 && !hasProtocolRE.test(maybeUrl)) {
    return { state: 'error', message: t('validation.invalid-protocol') };
    }
    if (isImage && !maybeUrl) {
    return { state: null, message: '' };
    }
    if (isImage && !/\.(png|jpg|jpeg|gif)$/.test(maybeUrl)) {
    return {
    state: 'error',
    message: t('validation.url-not-image')
    };
    }
    return isURL(maybeUrl)
    ? { state: 'success', message: '' }
    : { state: 'warning', message: t('validation.use-valid-url') };
    }


    We have had similar to what you are proposing ideas before: #40050

  3. BalanaguYashwanth commented on Feb 9, 2023

    @BalanaguYashwanth
    Contributor

    image

    Hey @Sboonny ,

    Can you close this ticket because i am not able to reproduce this issue, refer image. Developers can save time by looking into other issues

  4. removed
    status: waiting triage
    on Feb 9, 2023
  5. BalanaguYashwanth commented on Feb 9, 2023

    @BalanaguYashwanth
    Contributor

    Hello @Sboonny,

    Is this issue still active ?

    From above image i can see issue is solved, let me know any updates ?

    Reference - #49132 (comment)

  6. Sboonny commented on Feb 9, 2023

    @Sboonny
    MemberAuthor

    Your image indicate the existence of the issue, as campers couldn't know that the link they just copied into their image, isn't a valid image.

  7. BalanaguYashwanth commented on Feb 9, 2023

    @BalanaguYashwanth
    Contributor

    ok

  8. added
    help wanted
    on Mar 1, 2023
  9. Nirajn2311 commented on Mar 1, 2023

    @Nirajn2311
    Member

    We need to show a small preview of the image the user enters so that they know if the link will actually display the image or not.

  10. Sboonny commented on Mar 1, 2023

    @Sboonny
    Author
  11. bbsmooth commented on Mar 1, 2023

    @bbsmooth
    Contributor

    If the goal here is to let people know that the URL they put in the Picture input does/does not link to an image then we need to make sure everyone has access to this information. Showing a small preview of the image is fine, but that only helps people who can see the image. So we will need to make sure we include text that gives the same information (it can be sr-only text).

  12. ojeytonwilliams commented on Mar 2, 2023

    @ojeytonwilliams
    Contributor

    To clarify slightly, because I was confused:

    This issue is about the Portfolio Settings part of https://www.freecodecamp.org/settings, specifically adding and updating new portfolio items. It is not about the Personal Information section.

    However, since we correctly validate the Picture field in the Personal Information section, I propose we reuse that logic for the Image field of the portfolio item. That way, the a11y concerns @bbsmooth raised should be taken care of.

  13. Sboonny commented on Mar 20, 2023

    @Sboonny
    MemberAuthor

    I found a weird bug while trying to create styles for cards without image.

    Campers can bypass validation entirely through following this:

    If you have an empty portfolio item, and edit an existing one, you can have and empty portfolio item in your profile.

    rec-tab.25.webm

    Here is a live URL with empty portfolio item https://www.freecodecamp.org/Sboonny

  14. Anujvaid45 commented on Apr 15, 2023

    @Anujvaid45

    Hello @Sboonny
    The basic aim of this issue is to preview the image to user before uploading it in the portfolio section
    I am interested to work upon this issue
    So it would be nice if you will let me know whether I am following right path or not in understanding the issue
    Thank You!

  15. Sboonny commented on Apr 17, 2023

    @Sboonny
    MemberAuthor

    Welcome, @Anujvaid45.

    Yes you are following the right path, if you would like to fix this issue, please make sure you read our guidelines for contributing, we prioritize contributors following the instructions in our guides. Join us in our discord or the forum if you need help contributing, our prolific contributors will guide you through this.

  16. Anujvaid45 commented on Apr 18, 2023

    @Anujvaid45

    Hello @Sboonny
    So I was working on this issue and as mentioned on uploading the image url we wanted to display the preview of image right?
    So I have accordingly made changes in my code and its previewing the image after validating the url
    So is there anything else required to be done in this issue or should I improve the preview css?

  17. Sboonny commented on Apr 18, 2023

    @Sboonny
    MemberAuthor

    When I see the changes in a PR, I can give if there is something missing or if it needs an additional changes.

  18. Anujvaid45 commented on Apr 18, 2023

    @Anujvaid45

    Hello @Sboonny
    I have made the changes in code and you can see the result while adding image url in the portfolio section|
    So could you please see that and also suggest the required changes
    Meanwhile my tests are getting failed in the pull request, so meanwhile I am trying to solve those

  19. ShaunSHamilton commented on Apr 11, 2024

    @ShaunSHamilton
    Member

    @ojeytonwilliams and @Nirajn2311 I am just wanting clarification:

    Is the solution to show a preview of the image added? Or, to just follow the same logic we use in the "Personal Information" section to validate the URL?

  20. ojeytonwilliams commented on Apr 11, 2024

    @ojeytonwilliams
    Contributor

    Or, to just follow the same logic we use in the "Personal Information" section to validate the URL?

    That should be enough.

  21. Sembauke commented on Oct 29, 2024

    @Sembauke
    Member

    The Portfolio already seems to have image validation, are we talking about checking if the source directly links to an image by fetching the URL?

  22. ojeytonwilliams commented on Nov 4, 2024

    @ojeytonwilliams
    Contributor

    Yep, same as in settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedplatform: learn

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions