Fix downloads blocked for URLs with non-standard file extensions#242
Conversation
…iltering The isValidMediaUrl method in gallery.component.ts was filtering out URLs based on file extension, causing URLs with non-standard extensions (e.g. .bro) to be excluded from downloads. The check was too restrictive — any valid HTTP/HTTPS URL should be allowed through, with type detection handled by Content-Type headers via HEAD requests. Removed the extension whitelist from isValidMediaUrl. The function now only rejects data: and blob: URLs, plus non-HTTP/HTTPS schemes. Added tests for: - createFuskUrl and generateImageGallery with non-standard extensions (fuskr.service.spec.ts) - fallbackTypeDetection and HEAD-based detection for .bro URLs (media-type.service.spec.ts) - isValidMediaUrl accepting non-standard extensions (gallery.component.spec.ts) - getValidImageUrls including non-standard extension URLs (gallery.component.spec.ts)
DanAtkinson
left a comment
There was a problem hiding this comment.
What are the changes to package.json? The file should be LF and UTF-8.
The only change to |
There was a problem hiding this comment.
Pull request overview
This PR fixes Fuskr v5+ downloads being blocked for valid media URLs that use non-standard file extensions (e.g. .bro) by relaxing URL validation and adding regression tests around URL enumeration and media-type detection.
Changes:
- Simplified
GalleryComponent.isValidMediaUrlto allow any HTTP/HTTPS URL (still rejectingdata:andblob:). - Added tests ensuring
.broURLs are accepted by gallery URL filtering and that URL range generation works with non-standard extensions. - Added tests verifying media type detection can still resolve type via
Content-Type(HEAD) for non-standard extensions, and falls back gracefully on failure.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/app/components/gallery.component.ts | Removes extension whitelist gating; URL validity is now based on scheme/prefix checks only. |
| src/app/components/gallery.component.spec.ts | Adds regression tests for .bro URLs in getValidImageUrls and isValidMediaUrl. |
| src/app/services/fuskr.service.spec.ts | Adds coverage for fusk URL creation and gallery generation with non-standard extensions. |
| src/app/services/media-type.service.spec.ts | Adds coverage for .bro fallback detection + HEAD Content-Type-based detection behavior. |
| package.json | No functional dependency/script changes observed (appears to be a reformat/no-op change). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it('should include URLs with non-standard file extensions', () => { | ||
| const img = document.createElement('img'); | ||
| img.className = 'fusk-image'; | ||
| Object.defineProperty(img, 'complete', { value: true }); | ||
| Object.defineProperty(img, 'naturalHeight', { value: 100 }); | ||
| img.src = 'https://cdn.example.com/images/u598538_001.bro'; | ||
|
|
||
| document.body.appendChild(img); | ||
|
|
||
| const urls = ( | ||
| component as unknown as { | ||
| getValidImageUrls: () => string[]; | ||
| } | ||
| ).getValidImageUrls(); | ||
| expect(urls).toContain('https://cdn.example.com/images/u598538_001.bro'); | ||
| }); |
URLs with non-standard file extensions (e.g.
.bro) were silently excluded from downloads in Fuskr v5+, despite the images being valid and accessible. This broke patterns likehttp://cdn.gtresnews.com/zooms12/00000002723/u598538_[001-010].bro.Root cause
isValidMediaUrlingallery.component.tsused a hardcoded extension whitelist to gate download eligibility:Any URL whose path didn't end with a known extension returned
false, blocking it from the ZIP download. Fortype: 'unknown'items (which non-standard extensions get), this also blocked display.Changes
gallery.component.ts: Removed extension whitelist fromisValidMediaUrl. Now rejects onlydata:,blob:, and non-HTTP/HTTPS URLs. Type detection viaContent-Typeheaders (HEAD requests) is unaffected and handles actual media validation.Tests (
gallery.component.spec.ts,fuskr.service.spec.ts,media-type.service.spec.ts): Added coverage for non-standard extension URLs — confirming they passisValidMediaUrl, generate correct enumerated URL sequences, and resolve to the correct media type via HEAD request.