-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/sdp-core
- Loading branch information
Showing
32 changed files
with
202 additions
and
114 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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { getDpcPkgs } from './utils/index.js' | ||
export { stripMediaBaseUrl } from './utils/stripMediaBaseUrl.js' |
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
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
57 changes: 57 additions & 0 deletions
57
packages/ripple-tide-api/src/utils/stripMediaBaseUrl.test.ts
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,57 @@ | ||
import { expect, describe, it } from '@jest/globals' | ||
|
||
import stripMediaBaseUrl from './stripMediaBaseUrl.js' | ||
|
||
describe('stripMediaBaseUrl(url, baseUrl)', () => { | ||
it('strips the supplied baseUrl from the main url', () => { | ||
expect( | ||
stripMediaBaseUrl( | ||
'https://example.com/sites/default/files/wow/cool.jpg?some=param', | ||
'https://example.com' | ||
) | ||
).toEqual('/sites/default/files/wow/cool.jpg?some=param') | ||
|
||
expect( | ||
stripMediaBaseUrl( | ||
'https://example.com/sites/default/files/wow/cool.jpg?some=param', | ||
'https://example.com/' | ||
) | ||
).toEqual('/sites/default/files/wow/cool.jpg?some=param') | ||
}) | ||
|
||
it('does not change a url if it points to an external domain', () => { | ||
expect( | ||
stripMediaBaseUrl( | ||
'https://example.com/sites/default/files/wow/cool.jpg?some=param', | ||
'https://google.com' | ||
) | ||
).toEqual('https://example.com/sites/default/files/wow/cool.jpg?some=param') | ||
}) | ||
|
||
it('leaves relative URLs unchanged if the domains differ', () => { | ||
expect( | ||
stripMediaBaseUrl( | ||
'https://example.com/sites/default/files/wow/cool.jpg?some=param', | ||
'https://google.com' | ||
) | ||
).toEqual('https://example.com/sites/default/files/wow/cool.jpg?some=param') | ||
}) | ||
|
||
it('leaves relative URLs unchanged if no baseUrl is passed', () => { | ||
expect( | ||
stripMediaBaseUrl( | ||
'https://example.com/sites/default/files/wow/cool.jpg?some=param', | ||
'' | ||
) | ||
).toEqual('https://example.com/sites/default/files/wow/cool.jpg?some=param') | ||
}) | ||
|
||
it('only strips the base URL for media files matching sites/default/files', () => { | ||
expect( | ||
stripMediaBaseUrl( | ||
'https://example.com/sites/tmp/files/wow/cool.jpg', | ||
'https://example.com' | ||
) | ||
).toEqual('https://example.com/sites/tmp/files/wow/cool.jpg') | ||
}) | ||
}) |
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,13 @@ | ||
export function stripMediaBaseUrl(url: string, baseUrl: string): string { | ||
if (!url || typeof url !== 'string' || typeof baseUrl !== 'string') { | ||
return url | ||
} | ||
|
||
if (!url.includes('/sites/default/files/')) { | ||
return url | ||
} | ||
|
||
return url.replace(baseUrl.replace(/\/$/, ''), '') | ||
} | ||
|
||
export default stripMediaBaseUrl |
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
Oops, something went wrong.