forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 2
UFAL/Copy bitstream encoding name #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
43 changes: 43 additions & 0 deletions
43
src/app/core/url-serializer/bitstream-url-serializer.spec.ts
This file contains hidden or 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 { TestBed } from '@angular/core/testing'; | ||
| import { BitstreamUrlSerializer } from './bitstream-url-serializer'; | ||
| import { DefaultUrlSerializer, UrlTree } from '@angular/router'; | ||
|
|
||
| describe('BitstreamUrlSerializer', () => { | ||
| let serializer: BitstreamUrlSerializer; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| providers: [BitstreamUrlSerializer] | ||
| }); | ||
| serializer = TestBed.inject(BitstreamUrlSerializer); | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(serializer).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should not modify URLs that do not start with /bitstream/', () => { | ||
| const url = '/some/other/path/file.pdf'; | ||
| const result = serializer.parse(url); | ||
| const expected = new DefaultUrlSerializer().parse(url); | ||
| expect(result).toEqual(expected); | ||
| }); | ||
|
|
||
| it('should encode special characters in the filename in /bitstream/ URLs', () => { | ||
| const originalUrl = '/bitstream/id/123/456/some file(name)[v1].pdf'; | ||
| const expectedEncodedFilename = 'some%20file%28name%29%5Bv1%5D.pdf'; | ||
| const expectedUrl = `/bitstream/id/123/456/${expectedEncodedFilename}`; | ||
|
|
||
| const result: UrlTree = serializer.parse(originalUrl); | ||
|
|
||
| const resultUrl = new DefaultUrlSerializer().serialize(result); | ||
| expect(resultUrl).toBe(expectedUrl); | ||
| }); | ||
|
|
||
| it('should not modify /bitstream/ URL if there is no filename', () => { | ||
| const url = '/bitstream/id/123/456'; | ||
| const result = serializer.parse(url); | ||
| const expected = new DefaultUrlSerializer().parse(url); | ||
| expect(result).toEqual(expected); | ||
| }); | ||
| }); |
This file contains hidden or 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,27 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { DefaultUrlSerializer, UrlTree } from '@angular/router'; | ||
| import { encodeRFC3986URIComponent } from '../../shared/clarin-shared-util'; | ||
|
|
||
| /** | ||
| * This class intercepts the parsing of URLs to ensure that the filename in the URL is properly encoded. | ||
| * But it only does this for URLs that start with '/bitstream/'. | ||
| */ | ||
| @Injectable({ providedIn: 'root' }) | ||
| export class BitstreamUrlSerializer extends DefaultUrlSerializer { | ||
| FILENAME_INDEX = 5; | ||
| // Intercept parsing of every URL | ||
| parse(url: string): UrlTree { | ||
| if (url.startsWith('/bitstream/')) { | ||
| // Split the URL to isolate the filename | ||
| const parts = url.split('/'); | ||
| if (parts.length > this.FILENAME_INDEX) { | ||
| // Fetch the filename from the URL | ||
| 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('/'); | ||
| } | ||
| } | ||
| return super.parse(url); | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.