-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix: Unoptimized SVG images #7244
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d4f43c3
fix: unoptimized SVG image
canerakdas 4d16aa8
chore: review updates
canerakdas 1c66ced
Update apps/site/util/imageUtils.ts
canerakdas 2c7280e
chore: format files
canerakdas 88d3b0a
chore: review update
canerakdas 2697e02
Merge branch 'main' into fix/unoptimized-svg-image
ovflowd 5c79e59
Update apps/site/util/imageUtils.ts
ovflowd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { isSvgImage } from '@/util/imageUtils'; | ||
|
|
||
| describe('isSvgImage', () => { | ||
| const testCases = [ | ||
| { | ||
| description: 'should return true for a valid .svg URL', | ||
| input: 'https://nodejs.org/image.svg', | ||
| expected: true, | ||
| }, | ||
| { | ||
| description: 'should return true for a URL with query params', | ||
| input: 'https://nodejs.org/image.svg?query=param', | ||
| expected: true, | ||
| }, | ||
| { | ||
| description: 'should return false for a URL without a .svg extension', | ||
| input: 'https://nodejs.org/image', | ||
| expected: false, | ||
| }, | ||
| { | ||
| description: | ||
| 'should return false for a URL containing ".svg" but not ending with it', | ||
| input: 'https://nodejs.org/image.svg.png', | ||
| expected: false, | ||
| }, | ||
| { | ||
| description: 'should return false for an empty string', | ||
| input: '', | ||
| expected: false, | ||
| }, | ||
| { | ||
| description: 'should return false for a non-URL string', | ||
| input: 'not-a-url', | ||
| expected: false, | ||
| }, | ||
| ]; | ||
|
|
||
| testCases.forEach(({ description, input, expected }) => { | ||
| it(description, () => { | ||
| expect(isSvgImage(input)).toBe(expected); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| * This is a temporary workaround that can be removed once Next.js is upgraded. | ||
| * See https://github.com/vercel/next.js/pull/72970 | ||
| * | ||
| * Checks if the given source string points to an SVG image. | ||
ovflowd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * This function examines the base part of the provided string (ignoring query parameters) | ||
| * to determine if it ends with the `.svg` extension. | ||
| * | ||
| * @param src - The URL or string representing the source of the image. | ||
| * @returns `true` if the source points to an SVG image, otherwise `false`. | ||
| */ | ||
| export const isSvgImage = (src: string): boolean => { | ||
| // Split the source string at the '?' character to separate the main path from query parameters | ||
| const [image] = src.split('?'); | ||
|
|
||
| // Check if the base path (before any query parameters) ends with '.svg' | ||
| return image.endsWith('.svg'); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.