From 3109457960c1b0e61d4ae0e74a4b2edfdff150e7 Mon Sep 17 00:00:00 2001 From: zhiliu6 Date: Mon, 27 Jul 2020 17:12:44 +0800 Subject: [PATCH 1/4] Validate export file name --- src/services/assetService.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/services/assetService.ts b/src/services/assetService.ts index 2ab0ffabd0..60031b1e0a 100644 --- a/src/services/assetService.ts +++ b/src/services/assetService.ts @@ -176,6 +176,25 @@ export class AssetService { return metadata; } + /** + * Validate export file name + * @param asset - asset to process + */ + public validateFileName(asset: IAsset) { + try { + var newAssetName = asset.name.replace(/[*\\\/:?<>|]/g, m => "%" + m.charCodeAt(0).toString(16)); + + if (!newAssetName.toLowerCase().endsWith(asset.format)) + newAssetName = newAssetName + '.' + asset.format; + + if (newAssetName != asset.name) { + //console.log(`convert invalid file name '${asset.name}' to '${newAssetName}'`); + asset.name = newAssetName; + } + } catch (err) { + } + } + /** * Get metadata for asset * @param asset - Asset for which to retrieve metadata @@ -184,9 +203,14 @@ export class AssetService { Guard.null(asset); const fileName = `${asset.id}${constants.assetMetadataFileExtension}`; + + this.validateFileName(asset); + try { const json = await this.storageProvider.readText(fileName); - return JSON.parse(json) as IAssetMetadata; + const iAssetMetadata = JSON.parse(json) as IAssetMetadata; + this.validateFileName(iAssetMetadata.asset); + return iAssetMetadata; } catch (err) { if (asset.type === AssetType.TFRecord) { return { From 81f3fd8c8860bbdf918b51bb6a915fce58dc17bb Mon Sep 17 00:00:00 2001 From: zhiliu6 Date: Mon, 27 Jul 2020 17:18:31 +0800 Subject: [PATCH 2/4] remove unnecessary case conversion --- src/services/assetService.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/assetService.ts b/src/services/assetService.ts index 60031b1e0a..8d73f378a9 100644 --- a/src/services/assetService.ts +++ b/src/services/assetService.ts @@ -182,14 +182,14 @@ export class AssetService { */ public validateFileName(asset: IAsset) { try { - var newAssetName = asset.name.replace(/[*\\\/:?<>|]/g, m => "%" + m.charCodeAt(0).toString(16)); + var validFileName = asset.name.replace(/[*\\\/:?<>|]/g, m => "%" + m.charCodeAt(0).toString(16)); - if (!newAssetName.toLowerCase().endsWith(asset.format)) - newAssetName = newAssetName + '.' + asset.format; + if (!validFileName.endsWith(asset.format)) + validFileName = validFileName + '.' + asset.format; - if (newAssetName != asset.name) { + if (validFileName != asset.name) { //console.log(`convert invalid file name '${asset.name}' to '${newAssetName}'`); - asset.name = newAssetName; + asset.name = validFileName; } } catch (err) { } From a0a3aa97a3d6ff6bf18e89a91c7818269e7032eb Mon Sep 17 00:00:00 2001 From: zhiliu6 Date: Mon, 27 Jul 2020 17:29:58 +0800 Subject: [PATCH 3/4] meet ci requirement --- src/services/assetService.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/services/assetService.ts b/src/services/assetService.ts index 8d73f378a9..f99ff4662a 100644 --- a/src/services/assetService.ts +++ b/src/services/assetService.ts @@ -182,16 +182,18 @@ export class AssetService { */ public validateFileName(asset: IAsset) { try { - var validFileName = asset.name.replace(/[*\\\/:?<>|]/g, m => "%" + m.charCodeAt(0).toString(16)); + let validFileName = asset.name.replace(/[*\\\/:?<>|]/g, (c) => "%" + c.charCodeAt(0).toString(16)); - if (!validFileName.endsWith(asset.format)) - validFileName = validFileName + '.' + asset.format; + if (!validFileName.endsWith(asset.format)) { + validFileName = validFileName + "." + asset.format; + } - if (validFileName != asset.name) { - //console.log(`convert invalid file name '${asset.name}' to '${newAssetName}'`); + if (validFileName !== asset.name) { + // console.log(`convert invalid file name '${asset.name}' to '${validFileName}'`); asset.name = validFileName; } } catch (err) { + console.log(err); } } From b237d5b597628f4b644f9baef3562638ec4d1329 Mon Sep 17 00:00:00 2001 From: zhiliu6 Date: Thu, 13 Aug 2020 18:25:33 +0800 Subject: [PATCH 4/4] add & filter to avoid generate invalid xml char --- src/services/assetService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/assetService.ts b/src/services/assetService.ts index f99ff4662a..1e346d2649 100644 --- a/src/services/assetService.ts +++ b/src/services/assetService.ts @@ -182,7 +182,7 @@ export class AssetService { */ public validateFileName(asset: IAsset) { try { - let validFileName = asset.name.replace(/[*\\\/:?<>|]/g, (c) => "%" + c.charCodeAt(0).toString(16)); + let validFileName = asset.name.replace(/[*\\\/:?<>|&]/g, (c) => "%" + c.charCodeAt(0).toString(16)); if (!validFileName.endsWith(asset.format)) { validFileName = validFileName + "." + asset.format;