Skip to content

Commit

Permalink
Do not create blank alias names + Update ANTLR (#255)
Browse files Browse the repository at this point in the history
* No blank aliases when urls end with /

* Update antlr version to match SUSHI
  • Loading branch information
jafeltra authored Mar 14, 2024
1 parent 4af59b4 commit 30f9434
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
17 changes: 10 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"typescript": "^4.7.4"
},
"dependencies": {
"antlr4": "~4.8.0",
"antlr4": "~4.13.1-patch-1",
"chalk": "^4.1.0",
"commander": "^6.0.0",
"diff": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/optimizer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function resolveAliasFromURL(url: string, aliases: ExportableAlias[]): st
const parsedURL = new URL(url);
const rawAlias =
parsedURL.pathname && parsedURL.pathname !== '/'
? parsedURL.pathname?.split('/').slice(-1)[0]
? parsedURL.pathname?.split('/').slice(parsedURL.pathname.endsWith('/') ? -2 : -1)[0]
: parsedURL.hostname?.replace('www.', '').split('.')[0];

if (rawAlias == null) {
Expand Down
10 changes: 10 additions & 0 deletions test/optimizer/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ describe('optimizer', () => {
url: 'http://example.org/foo-bar_3.1~te$t'
});
});

it('should ensure newly created aliases are not ONLY $', () => {
const originalLength = aliases.length;
expect(resolveAliasFromURL('http://example.org/foo-bar/', aliases)).toBe('$foo-bar');
expect(aliases).toHaveLength(originalLength + 1);
expect(aliases[aliases.length - 1]).toEqual({
alias: '$foo-bar',
url: 'http://example.org/foo-bar/'
});
});
});
});
});

0 comments on commit 30f9434

Please sign in to comment.