Added empty array checks using Utils method
MODIFY
src/server/rest/v1/service/security/AssetSecurity.ts
src/server/rest/v1/service/security/AssetSecurity.ts
@@ -69,7 +69,7 @@ export default class AssetSecurity {
filteredRequest.staticValueWatt = sanitize(request.staticValueWatt),
filteredRequest.image = request.image;
filteredRequest.dynamicAsset = UtilsSecurity.filterBoolean(request.dynamicAsset);
- if (Utils.objectHasProperty(request, 'coordinates') && request.coordinates.length === 2) {
+ if (Utils.objectHasProperty(request, 'coordinates') && !Utils.isEmptyArray(request.coordinates) && request.coordinates.length === 2) {
filteredRequest.coordinates = [
sanitize(request.coordinates[0]),
sanitize(request.coordinates[1])

MODIFY
src/server/rest/v1/service/security/ChargingStationSecurity.ts
src/server/rest/v1/service/security/ChargingStationSecurity.ts
@@ -142,14 +142,14 @@ export default class ChargingStationSecurity {
if (Utils.objectHasProperty(request, 'siteAreaID')) {
filteredRequest.siteAreaID = sanitize(request.siteAreaID);
}
- if (Utils.objectHasProperty(request, 'coordinates') && request.coordinates.length === 2) {
+ if (Utils.objectHasProperty(request, 'coordinates') && !Utils.isEmptyArray(request.coordinates) && request.coordinates.length === 2) {
filteredRequest.coordinates = [
sanitize(request.coordinates[0]),
sanitize(request.coordinates[1])
];
}
// Filter connectors
- if (Utils.objectHasProperty(request, 'connectors')) {
+ if (Utils.objectHasProperty(request, 'connectors') && !Utils.isEmptyArray(request.connectors)) {
filteredRequest.connectors = request.connectors.map((connector) => {
if (connector) {
return {

MODIFY
src/server/rest/v1/service/security/TransactionSecurity.ts
src/server/rest/v1/service/security/TransactionSecurity.ts
@@ -6,7 +6,7 @@ import sanitize from 'mongo-sanitize';
export default class TransactionSecurity {
public static filterTransactionsRefund(request: any): HttpTransactionsRefundRequest {
- if (!Utils.objectHasProperty(request, 'transactionIds')) {
+ if (!Utils.objectHasProperty(request, 'transactionIds') || Utils.isEmptyArray(request.transactionIds)) {
return { transactionIds: [] };
}
return { transactionIds: request.transactionIds.map(sanitize) };

MODIFY
src/server/rest/v1/service/security/UtilsSecurity.ts
src/server/rest/v1/service/security/UtilsSecurity.ts
@@ -115,12 +115,7 @@ export default class UtilsSecurity {
filteredAddress.department = sanitize(address.department);
filteredAddress.region = sanitize(address.region);
filteredAddress.country = sanitize(address.country);
- if (Utils.objectHasProperty(address, 'coordinates') && address.coordinates.length === 2) {
- filteredAddress.coordinates = [
- sanitize(address.coordinates[0]),
- sanitize(address.coordinates[1])
- ];
- }
+ UtilsSecurity.filterAddressCoordinatesRequest(address);
}
return filteredAddress;
}
@@ -128,7 +123,7 @@ export default class UtilsSecurity {
static filterAddressCoordinatesRequest(address: Address): Address {
const filteredAddress: Address = {} as Address;
if (address) {
- if (Utils.objectHasProperty(address, 'coordinates') && address.coordinates.length === 2) {
+ if (Utils.objectHasProperty(address, 'coordinates') && !Utils.isEmptyArray(address.coordinates) && address.coordinates.length === 2) {
filteredAddress.coordinates = [
sanitize(address.coordinates[0]),
sanitize(address.coordinates[1])

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1131,7 +1131,7 @@ export default class Utils {
public static containsGPSCoordinates(coordinates: number[]): boolean {
// Check if GPs are available
- if (coordinates && coordinates.length === 2 && coordinates[0] && coordinates[1]) {
+ if (!Utils.isEmptyArray(coordinates) && coordinates.length === 2 && coordinates[0] && coordinates[1]) {
// Check Longitude & Latitude
if (new RegExp(Constants.REGEX_VALIDATION_LONGITUDE).test(coordinates[0].toString()) &&
new RegExp(Constants.REGEX_VALIDATION_LATITUDE).test(coordinates[1].toString())) {

Added empty array checks using Utils method