Skip to content

Commit

Permalink
fix: corrige vulnerabilidades mapeadas pelo sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
jnrpalma authored and pedrodominguesp committed Nov 8, 2024
1 parent 61090da commit 2ba3ccb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 21 additions & 1 deletion projects/ui/src/lib/utils/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
removeDuplicatedOptionsWithFieldValue,
removeUndefinedAndNullOptionsWithFieldValue,
isValidImageBase64,
sortArrayOfObjects
sortArrayOfObjects,
isValidUrl
} from './util';

import * as UtilFunctions from './util';
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion projects/ui/src/lib/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2ba3ccb

Please sign in to comment.