Skip to content

Commit c98ac21

Browse files
bengummerCompuIves
authored andcommitted
handle different GitHub URL input formats (codesandbox#56)
1 parent 11a0105 commit c98ac21

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/app/utils/url-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ export const optionsToParameterizedUrl = (options: Object) => {
8989
};
9090

9191
export const gitHubToSandboxUrl = (githubUrl: string) =>
92-
githubUrl.replace('https://github.com', '/s/github');
92+
githubUrl.replace(/https?:\/\/(www.)?github.com/, '/s/github');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { gitHubToSandboxUrl } from './url-generator';
2+
3+
describe('url-generator', () => {
4+
describe('gitHubToSandboxUrl', () => {
5+
[
6+
'http://github.com/user/repo',
7+
'http://www.github.com/user/repo',
8+
'https://github.com/user/repo',
9+
'https://www.github.com/user/repo'
10+
].forEach(inputUrl => {
11+
test(`handles ${inputUrl} urls`, () => {
12+
expect(gitHubToSandboxUrl(inputUrl)).toBe('/s/github/user/repo');
13+
});
14+
})
15+
});
16+
});

0 commit comments

Comments
 (0)