-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api-client): sanitize file name thoroughly (#15062)
more thoroughly remove all spaces and special characters from splash file name closes RQA-2668
- Loading branch information
1 parent
b15af5e
commit 044be7a
Showing
4 changed files
with
28 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { sanitizeFileName } from '../utils' | ||
|
||
describe('sanitizeFileName', () => { | ||
it('returns original alphanumeric file name', () => { | ||
expect(sanitizeFileName('an0ther_otie_logo.png')).toEqual( | ||
'an0ther_otie_logo.png' | ||
) | ||
}) | ||
|
||
it('sanitizes a file name', () => { | ||
expect( | ||
sanitizeFileName( | ||
`otie's birthday/party - (& the bouncy castle cost ~$100,000).jpeg` | ||
) | ||
).toEqual( | ||
'otie_s_birthday_party_-____the_bouncy_castle_cost___100_000_.jpeg' | ||
) | ||
}) | ||
}) |
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,3 @@ | ||
export function sanitizeFileName(fileName: string): string { | ||
return fileName.replace(/[^a-zA-Z0-9-.]/gi, '_') | ||
} |