-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: first parse url and then path to retrieve extension (#9011)
* First parse url and then path to retrieve extension * Move out extension parsing to unittest * Prettify test * Rename test file to match source file
- Loading branch information
1 parent
ccc3082
commit eb7648c
Showing
3 changed files
with
32 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { getRemoteFileExtension } = require(`../utils`) | ||
|
||
describe(`create remote file node`, () => { | ||
it(`can correctly retrieve files extensions`, () => { | ||
[ | ||
[`https://scontent.xx.fbcdn.net/v/t51.2885-15/42078503_294439751160571_1602896118583132160_n.jpg?_nc_cat=101&oh=e30490a47409051c45dc3daacf616bc0&oe=5C5EA8EB`, `.jpg`], | ||
[`https://facebook.com/hello,_world_asdf12341234.jpeg?test=true&other_thing=also-true`, `.jpeg`], | ||
[`https://test.com/asdf.png`, `.png`], | ||
[`./path/to/relative/file.tiff`, `.tiff`], | ||
[`/absolutely/this/will/work.bmp`, `.bmp`], | ||
].forEach(([url, ext]) => { | ||
expect(getRemoteFileExtension(url)).toBe(ext) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const path = require(`path`) | ||
const Url = require(`url`) | ||
|
||
/** | ||
* getRemoteFileExtension | ||
* -- | ||
* Parses remote url to retrieve remote file extension | ||
* | ||
* | ||
* @param {String} url | ||
* @return {String} extension | ||
*/ | ||
export function getRemoteFileExtension(url) { | ||
return path.parse(Url.parse(url).pathname).ext | ||
} |