Skip to content

Commit

Permalink
fix: handle 'split' being called on undefined when invalid url value …
Browse files Browse the repository at this point in the history
…specified
  • Loading branch information
allenevans committed Feb 17, 2020
1 parent 0a1520a commit c833cbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/url-parameter-append.spec.ts
Expand Up @@ -131,4 +131,19 @@ describe('urlParameterAppend', () => {
expect(result).toEqual('http://example.com/?updated=true&added=yes');
});
});

describe('edge cases', () => {
it('should default url to empty string if no url is defined', () => {
// @ts-ignore
const result = urlParameterAppend(undefined as any, 'param', 'value');

expect(result).toEqual('?param=value');
});

it('should default url to empty string if no url is defined', () => {
const result = urlParameterAppend(null as any, 'param', 'value');

expect(result).toEqual('?param=value');
});
});
});
2 changes: 1 addition & 1 deletion src/url-parameter-append.ts
Expand Up @@ -18,7 +18,7 @@ export default function urlParameterAppend(url: string, ...args: any[]): string
}

// tslint:disable-next-line:prefer-const
let [modifiedUrl, ...fragment] = url.split('#');
let [modifiedUrl, ...fragment] = (url ?? '').split('#');

for (let i = 0; i < args.length; i += 2) {
const param = args[i];
Expand Down

0 comments on commit c833cbb

Please sign in to comment.