From 30f9434e34c35200c24ce5f8bd9ee29704420c1d Mon Sep 17 00:00:00 2001 From: Julia Afeltra <30803904+jafeltra@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:25:08 -0400 Subject: [PATCH] Do not create blank alias names + Update ANTLR (#255) * No blank aliases when urls end with / * Update antlr version to match SUSHI --- package-lock.json | 17 ++++++++++------- package.json | 2 +- src/optimizer/utils.ts | 2 +- test/optimizer/utils.test.ts | 10 ++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 16607e49..55ed32e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.3.0", "license": "Apache-2.0", "dependencies": { - "antlr4": "~4.8.0", + "antlr4": "~4.13.1-patch-1", "chalk": "^4.1.0", "commander": "^6.0.0", "diff": "^5.0.0", @@ -1873,9 +1873,12 @@ } }, "node_modules/antlr4": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/antlr4/-/antlr4-4.8.0.tgz", - "integrity": "sha512-en/MxQ4OkPgGJQ3wD/muzj1uDnFSzdFIhc2+c6bHZokWkuBb6RRvFjpWhPxWLbgQvaEzldJZ0GSQpfSAaE3hqg==" + "version": "4.13.1-patch-1", + "resolved": "https://registry.npmjs.org/antlr4/-/antlr4-4.13.1-patch-1.tgz", + "integrity": "sha512-OjFLWWLzDMV9rdFhpvroCWR4ooktNg9/nvVYSA5z28wuVpU36QUNuioR1XLnQtcjVlf8npjyz593PxnU/f/Cow==", + "engines": { + "node": ">=16" + } }, "node_modules/anymatch": { "version": "3.1.3", @@ -8320,9 +8323,9 @@ } }, "antlr4": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/antlr4/-/antlr4-4.8.0.tgz", - "integrity": "sha512-en/MxQ4OkPgGJQ3wD/muzj1uDnFSzdFIhc2+c6bHZokWkuBb6RRvFjpWhPxWLbgQvaEzldJZ0GSQpfSAaE3hqg==" + "version": "4.13.1-patch-1", + "resolved": "https://registry.npmjs.org/antlr4/-/antlr4-4.13.1-patch-1.tgz", + "integrity": "sha512-OjFLWWLzDMV9rdFhpvroCWR4ooktNg9/nvVYSA5z28wuVpU36QUNuioR1XLnQtcjVlf8npjyz593PxnU/f/Cow==" }, "anymatch": { "version": "3.1.3", diff --git a/package.json b/package.json index aebb6ab4..f70e90e7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/optimizer/utils.ts b/src/optimizer/utils.ts index 4d07fb55..1881f7cf 100644 --- a/src/optimizer/utils.ts +++ b/src/optimizer/utils.ts @@ -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) { diff --git a/test/optimizer/utils.test.ts b/test/optimizer/utils.test.ts index 7e7c9cfb..41b16f5f 100644 --- a/test/optimizer/utils.test.ts +++ b/test/optimizer/utils.test.ts @@ -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/' + }); + }); }); }); });