mirror of
https://github.com/layer-systems/website.git
synced 2026-09-12 21:53:40 +02:00
Validate saved wallpaper URLs
Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9c01835527
commit
0f43066137
@@ -42,8 +42,10 @@ let instances: FakeImage[] = [];
|
||||
|
||||
describe('WallpaperSection', () => {
|
||||
let originalImage: typeof Image;
|
||||
let originalResizeObserver: typeof ResizeObserver;
|
||||
|
||||
beforeEach(() => {
|
||||
originalResizeObserver = global.ResizeObserver;
|
||||
global.ResizeObserver = StubResizeObserver as unknown as typeof ResizeObserver;
|
||||
instances = [];
|
||||
originalImage = globalThis.Image;
|
||||
@@ -52,6 +54,7 @@ describe('WallpaperSection', () => {
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.Image = originalImage;
|
||||
global.ResizeObserver = originalResizeObserver;
|
||||
});
|
||||
|
||||
it('shows the dot-grid curated wallpaper selected by default', async () => {
|
||||
|
||||
@@ -221,6 +221,10 @@ export function WallpaperSection() {
|
||||
toast({ title: 'Preview the image before saving it', variant: 'destructive' });
|
||||
return;
|
||||
}
|
||||
if (previewedUrl.length > MAX_WALLPAPER_URL_LENGTH) {
|
||||
toast({ title: 'That URL is too long', description: `URLs must be ${MAX_WALLPAPER_URL_LENGTH} characters or fewer.`, variant: 'destructive' });
|
||||
return;
|
||||
}
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
wallpaper: { version: 1, selection: { source: 'url', url: previewedUrl, presentation: { fit, dim } } },
|
||||
@@ -271,6 +275,7 @@ export function WallpaperSection() {
|
||||
const tags = await uploadFile(sanitizedFile);
|
||||
const uploadedUrl = tags.find(([name, value]) => name === 'url' && value)?.[1];
|
||||
if (!uploadedUrl || !isSafeWallpaperUrl(uploadedUrl)) throw new Error('Upload did not return a safe image URL.');
|
||||
if (uploadedUrl.length > MAX_WALLPAPER_URL_LENGTH) throw new Error(`Upload returned a URL longer than ${MAX_WALLPAPER_URL_LENGTH} characters.`);
|
||||
|
||||
setUrlDraft(uploadedUrl);
|
||||
setPendingPreviewUrl(uploadedUrl);
|
||||
|
||||
Reference in New Issue
Block a user