-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add truncation for image URLs #21242
Changes from all commits
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,5 +19,26 @@ export function filterURLForDisplay( url ) { | |||||||||||
return filteredURL.replace( '/', '' ); | ||||||||||||
} | ||||||||||||
|
||||||||||||
// Prettify image urls | ||||||||||||
const mediaRegexp = /([\w|:])*\.(?:jpg|jpeg|gif|png|svg)/g; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to be matching this globally? Are we expecting multiple matches?
Suggested change
|
||||||||||||
const colon = ':'; | ||||||||||||
const period = '.'; | ||||||||||||
const query = '?'; | ||||||||||||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these serving much purpose? A few points I'd make:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed using
will return a nice object with all the elements decomposed like this:
so less need to split/join strings. |
||||||||||||
if ( filteredURL.match( mediaRegexp ) ) { | ||||||||||||
let tokens = filteredURL.split( '/' ); | ||||||||||||
let imageToken = tokens[ tokens.length - 1 ]; | ||||||||||||
if ( imageToken.includes( query ) ) { | ||||||||||||
imageToken = imageToken.split( query )[ 0 ]; | ||||||||||||
} | ||||||||||||
if ( tokens[ 0 ].includes( colon ) ) { | ||||||||||||
tokens = tokens[ 0 ].split( colon ); | ||||||||||||
} | ||||||||||||
if ( tokens[ 0 ].includes( period ) ) { | ||||||||||||
tokens = tokens[ 0 ].split( period ); | ||||||||||||
} | ||||||||||||
const prettifiedImageURL = tokens[ 0 ] + '...' + imageToken; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems an ellipsis character Related:
|
||||||||||||
return prettifiedImageURL; | ||||||||||||
} | ||||||||||||
|
||||||||||||
return filteredURL; | ||||||||||||
} |
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.
All tests pass if I change this to...
I'd wonder then:
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.
It looks safe to check only for extensions but that would include all kinds of media extensions (audio and video too)