diff --git a/package.json b/package.json index e10fbed4d7..a21ae2eeee 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "ng-packagr": "~17.0.2", "prettier": "^3.1.0", "protractor": "~7.0.0", - "rollup": "4.6.0", + "rollup": "4.24.4", "sonarjs": "latest", "sonarqube-scanner": "^3.3.0", "standard-version": "^9.5.0", diff --git a/projects/ui/src/lib/utils/util.spec.ts b/projects/ui/src/lib/utils/util.spec.ts index 02cca3c157..3cd6f17d43 100644 --- a/projects/ui/src/lib/utils/util.spec.ts +++ b/projects/ui/src/lib/utils/util.spec.ts @@ -33,7 +33,8 @@ import { removeDuplicatedOptionsWithFieldValue, removeUndefinedAndNullOptionsWithFieldValue, isValidImageBase64, - sortArrayOfObjects + sortArrayOfObjects, + isValidUrl } from './util'; import * as UtilFunctions from './util'; @@ -164,6 +165,25 @@ describe('Function isLanguage:', () => { }); }); +describe('isValidUrl', () => { + it('should return true for the current page URL', () => { + const mockLocation = { origin: 'http://localhost', pathname: '/current-path' } as Location; + const currentUrl = 'http://localhost/current-path'; + expect(isValidUrl(currentUrl, mockLocation)).toBe(true); + }); + + it('should return false for a different URL', () => { + const mockLocation = { origin: 'http://localhost', pathname: '/current-path' } as Location; + const differentUrl = 'http://localhost/different-path'; + expect(isValidUrl(differentUrl, mockLocation)).toBe(false); + }); + + it('should use window.location as the default location', () => { + const currentUrl = window.location.origin + window.location.pathname; + expect(isValidUrl(currentUrl)).toBe(true); + }); +}); + describe('Function formatBytes:', () => { it('formatBytes: should return undefined if bytes is undefined', () => { const bytes = undefined; diff --git a/projects/ui/src/lib/utils/util.ts b/projects/ui/src/lib/utils/util.ts index af44777f55..0ca0e466e5 100644 --- a/projects/ui/src/lib/utils/util.ts +++ b/projects/ui/src/lib/utils/util.ts @@ -67,7 +67,15 @@ export function isLanguage(value) { /* istanbul ignore next */ export function reloadCurrentPage() { - window.location.assign(location.href); + const currentUrl = window.location.origin + window.location.pathname; + + if (isValidUrl(currentUrl)) { + window.location.assign(currentUrl); + } +} + +export function isValidUrl(url: string, location: Location = window.location): boolean { + return url === location.origin + location.pathname; } export function convertToBoolean(val: any): boolean {