Skip to content
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

url: filterURLForDisplay only considers basic image extensions #53154

Closed
t-hamano opened this issue Jul 30, 2023 · 1 comment · Fixed by #54920
Closed

url: filterURLForDisplay only considers basic image extensions #53154

t-hamano opened this issue Jul 30, 2023 · 1 comment · Fixed by #54920
Assignees
Labels
[Package] Url /packages/url [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@t-hamano
Copy link
Contributor

t-hamano commented Jul 30, 2023

Related to #27530

What problem does this address?

The filterURLForDisplay() function in the url package properly processes the given URL string and generates a string for display. This function accomplishes two main things:

  • Remove protocol and www subdomain
  • If maxLength is given and the URL is a media filename, return the filename containing an ellipsis

Examples of various conversions can be seen in this unit test.

However, only basic image extensions are considered when rounding strings.

const mediaRegexp = /([\w|:])*\.(?:jpg|jpeg|gif|png|svg)/;

As a result, URLs in popovers may overflow in LinkControl components that use this function, for example.

Expected

URL with jpg image

jpg_image

Unexpected

URL with webp image

webp_image

URL with mp4 video

mp4_video

What is your proposed solution?

I would suggest either of the following approaches:

  • Consider all extensions that can be uploaded to WordPress. (mime_types filter may be helpful)
  • All extensions to be rounded up by maxLength

Step-by-step reproduction instructions

N/A

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@t-hamano t-hamano added the [Package] Url /packages/url label Jul 30, 2023
@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Aug 1, 2023
@brookewp brookewp added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. labels Sep 14, 2023
@brookewp
Copy link
Contributor

Thanks for opening the issue! I encountered this in the Video block since it uses the same logic. However, I'm not seeing a scroll bar, so the edit button can be difficult to use:

Screenshot 2023-09-13 at 6 14 34 PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Url /packages/url [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
3 participants