-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: unoptimized SVG image * chore: review updates * Update apps/site/util/imageUtils.ts Co-authored-by: Steven <[email protected]> Signed-off-by: Caner Akdas <[email protected]> * chore: format files * chore: review update * Update apps/site/util/imageUtils.ts Co-authored-by: Steven <[email protected]> Signed-off-by: Claudio W <[email protected]> --------- Signed-off-by: Caner Akdas <[email protected]> Signed-off-by: Claudio W <[email protected]> Co-authored-by: Steven <[email protected]> Co-authored-by: Claudio W <[email protected]>
- Loading branch information
1 parent
635f2b3
commit 78c14bd
Showing
4 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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. | ||
* | ||
* 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'); | ||
}; |