Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/core/url-serializer/bitstream-url-serializer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ describe('BitstreamUrlSerializer', () => {
const expected = new DefaultUrlSerializer().parse(url);
expect(result).toEqual(expected);
});

it('should encode the filename and preserve query parameters in /bitstream/ URLs', () => {
const originalUrl = '/bitstream/handle/123/456/some file.pdf?sequence=3&isAllowed=y';
const expectedEncodedFilename = 'some%20file.pdf';
const expectedUrl = `/bitstream/handle/123/456/${expectedEncodedFilename}?sequence=3&isAllowed=y`;

const result: UrlTree = serializer.parse(originalUrl);

const resultUrl = new DefaultUrlSerializer().serialize(result);
expect(resultUrl).toBe(expectedUrl);
});
});
18 changes: 12 additions & 6 deletions src/app/core/url-serializer/bitstream-url-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ export class BitstreamUrlSerializer extends DefaultUrlSerializer {
// Intercept parsing of every URL
parse(url: string): UrlTree {
if (url.startsWith('/bitstream/')) {
// Split the URL to isolate the filename
const parts = url.split('/');
// Separate the path from the query string
const [path, query] = url.split('?');

// Split the path to isolate the filename
const parts = path.split('/');
if (parts.length > this.FILENAME_INDEX) {
// Fetch the filename from the URL
const filename = parts.slice(this.FILENAME_INDEX).join();
const filename = parts.slice(this.FILENAME_INDEX).join('/');
const encodedFilename = encodeRFC3986URIComponent(filename);
// Reconstruct the URL with the encoded filename
url = [...parts.slice(0, this.FILENAME_INDEX), encodedFilename].join('/');

// Reconstruct the path with the encoded filename
const newPath = [...parts.slice(0, this.FILENAME_INDEX), encodedFilename].join('/');

// Reattach query string if present
url = query ? `${newPath}?${query}` : newPath;
}
}
return super.parse(url);
Expand Down