From 0934500c0199faf50876786419e3468c6225a7bb Mon Sep 17 00:00:00 2001 From: Miguel Alves Date: Mon, 23 Oct 2023 13:31:02 +0100 Subject: [PATCH] RDEV-5995 Fixed sanitization of command-line parameters (#157) * Revert "RDEV-5995 Fixed quotes in webpack configuration (#156)" This reverts commit a2121c4ce24f92d24f826978e49d92b86abde4ff. * RDEV-5995 Fixed sanitization of command-line parameters * CR --- ViewGenerator/ViewGenerator.csproj | 2 +- ViewGenerator/build/ViewGenerator.targets | 6 +++--- ViewGenerator/tools/webpack/Plugins/Utils.ts | 16 ++++++++++++---- ViewGenerator/tools/webpack/Rules/Files.ts | 8 ++++---- ViewGenerator/tools/webpack/tsconfig.json | 5 ++++- .../tools/webpack/webpack_plugins.config.ts | 4 ++-- .../tools/webpack/webpack_stylesheets.config.ts | 12 ++++++------ .../tools/webpack/webpack_views.config.ts | 8 +++++--- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/ViewGenerator/ViewGenerator.csproj b/ViewGenerator/ViewGenerator.csproj index 584ca0a3..f96a3bb1 100644 --- a/ViewGenerator/ViewGenerator.csproj +++ b/ViewGenerator/ViewGenerator.csproj @@ -7,7 +7,7 @@ ViewGenerator ViewGenerator Generates .NET View bindings from typescript - 1.1.12 + 1.1.13 ViewGenerator Library diff --git a/ViewGenerator/build/ViewGenerator.targets b/ViewGenerator/build/ViewGenerator.targets index 98751f36..b849ba4b 100644 --- a/ViewGenerator/build/ViewGenerator.targets +++ b/ViewGenerator/build/ViewGenerator.targets @@ -139,19 +139,19 @@ - + - + - + diff --git a/ViewGenerator/tools/webpack/Plugins/Utils.ts b/ViewGenerator/tools/webpack/Plugins/Utils.ts index f31ff183..18e216c3 100644 --- a/ViewGenerator/tools/webpack/Plugins/Utils.ts +++ b/ViewGenerator/tools/webpack/Plugins/Utils.ts @@ -94,13 +94,21 @@ export function generateManifest( export function getCurrentDirectory() { return resolve("."); } + /* * Gets the filename from an array. * */ -export function getFileName(relativePaths: Dictionary, chunkData: any) { - const Directory: string = relativePaths[chunkData.chunk.name]; - if (Directory) { - return Directory + JsPlaceholder; +export function getFileName(relativePaths: Dictionary, chunkData: any): string { + const directory: string = relativePaths[chunkData.chunk.name]; + if (directory) { + return directory + JsPlaceholder; } return OutputDirectoryDefault + JsChunkPlaceholder; +} + +/* + * Sanitizes a command-line parameter + * */ +export function sanitizeCommandLineParam(parameter: string): string { + return parameter.replaceAll("'", ""); } \ No newline at end of file diff --git a/ViewGenerator/tools/webpack/Rules/Files.ts b/ViewGenerator/tools/webpack/Rules/Files.ts index 2f4394a8..b5a152b4 100644 --- a/ViewGenerator/tools/webpack/Rules/Files.ts +++ b/ViewGenerator/tools/webpack/Rules/Files.ts @@ -21,15 +21,15 @@ const getResourcesRuleSet = (assemblyName?: string, pluginsBase? : string): Rule } if (pathData.module) { - let module: NormalModule = pathData.module as NormalModule; + const module: NormalModule = pathData.module as NormalModule; if (module.resourceResolveData) { - let resourceResolveData = module.resourceResolveData; - let assemblyFileName = resourceResolveData.descriptionFileData.name; + const resourceResolveData = module.resourceResolveData; + const assemblyFileName = resourceResolveData.descriptionFileData.name; if (assemblyFileName.toUpperCase() === assemblyName.toUpperCase()) { return assemblyName + '/' + pathData.filename; } - if (!!pluginsBase && assemblyFileName.toUpperCase() === pluginsBase.toUpperCase()) { + if (pluginsBase && assemblyFileName.toUpperCase() === pluginsBase.toUpperCase()) { return pluginsBase + '/' + pathData.filename; } diff --git a/ViewGenerator/tools/webpack/tsconfig.json b/ViewGenerator/tools/webpack/tsconfig.json index d170e315..1bf43337 100644 --- a/ViewGenerator/tools/webpack/tsconfig.json +++ b/ViewGenerator/tools/webpack/tsconfig.json @@ -3,7 +3,10 @@ "module": "commonjs", "target": "es6", "esModuleInterop": true, - "skipLibCheck": true + "skipLibCheck": true, + "lib": [ + "ES2021.String" + ] }, "compileOnSave": true, "exclude": [ diff --git a/ViewGenerator/tools/webpack/webpack_plugins.config.ts b/ViewGenerator/tools/webpack/webpack_plugins.config.ts index 60aad28f..b4c62865 100644 --- a/ViewGenerator/tools/webpack/webpack_plugins.config.ts +++ b/ViewGenerator/tools/webpack/webpack_plugins.config.ts @@ -4,11 +4,11 @@ import getCommonConfiguration from "./Plugins/CommonConfiguration"; import DtsCleanupPlugin from "./Plugins/DtsCleanupPlugin"; import DtsGeneratorPlugin from "./Plugins/DtsGeneratorPlugin"; import { DtsFileName } from "./Plugins/Resources"; -import { getCurrentDirectory } from "./Plugins/Utils"; +import { getCurrentDirectory, sanitizeCommandLineParam } from "./Plugins/Utils"; const config = (env) => { - let standardConfig: Configuration = getCommonConfiguration("Plugins", env.useCache, env.assemblyName); + const standardConfig: Configuration = getCommonConfiguration("Plugins", env.useCache, sanitizeCommandLineParam(env.assemblyName)); (standardConfig.cache as any).name = "pluginsCache"; diff --git a/ViewGenerator/tools/webpack/webpack_stylesheets.config.ts b/ViewGenerator/tools/webpack/webpack_stylesheets.config.ts index 9e988cbe..da4ccee1 100644 --- a/ViewGenerator/tools/webpack/webpack_stylesheets.config.ts +++ b/ViewGenerator/tools/webpack/webpack_stylesheets.config.ts @@ -4,7 +4,7 @@ import { Configuration } from "webpack"; import MiniCssExtractPluginCleanup from "./Plugins/MiniCssExtractPluginCleanup"; import { CssPlaceholder, JsMapPlaceholder, OutputDirectoryDefault } from "./Plugins/Resources"; -import { Dictionary, getCurrentDirectory } from "./Plugins/Utils" +import { Dictionary, getCurrentDirectory, sanitizeCommandLineParam } from "./Plugins/Utils" import getResourcesRuleSet from "./Rules/Files"; import SassRuleSet from "./Rules/Sass"; @@ -12,15 +12,15 @@ import SassRuleSet from "./Rules/Sass"; const config = (env) => { const getEntryName = (entryPath: string): string => { - let fileExtensionLen: number = entryPath.length - entryPath.lastIndexOf("."); + const fileExtensionLen: number = entryPath.length - entryPath.lastIndexOf("."); return entryPath.slice(entryPath.replace(/\//g, '\\').lastIndexOf("\\") + 1, -fileExtensionLen); }; - let entries: string = env.entryPath; + let entries: string = sanitizeCommandLineParam(env.entryPath); let entryMap: Dictionary = {}; entries.split(";").map(entryPath => entryMap[getEntryName(entryPath)] = './' + entryPath) - - let stylesheetsConfig: Configuration = { + + const stylesheetsConfig: Configuration = { entry: entryMap, output: { @@ -42,7 +42,7 @@ const config = (env) => { module: { rules: [ SassRuleSet, - getResourcesRuleSet(env.assemblyName) + getResourcesRuleSet(sanitizeCommandLineParam(env.assemblyName)) ] }, diff --git a/ViewGenerator/tools/webpack/webpack_views.config.ts b/ViewGenerator/tools/webpack/webpack_views.config.ts index 0ec6eaec..fa0fc3bf 100644 --- a/ViewGenerator/tools/webpack/webpack_views.config.ts +++ b/ViewGenerator/tools/webpack/webpack_views.config.ts @@ -3,7 +3,7 @@ import { resolve } from "path"; import { Configuration } from "webpack"; import getCommonConfiguration from "./Plugins/CommonConfiguration"; -import { Dictionary } from "./Plugins/Utils"; +import { Dictionary, sanitizeCommandLineParam } from "./Plugins/Utils"; const config = (env) => { @@ -34,8 +34,10 @@ const config = (env) => { throw new Error("Extended configuration file not found."); } }; + + const sanitizedPluginsRelativePath: string = sanitizeCommandLineParam(env.pluginsRelativePath); - let standardConfig: Configuration = getCommonConfiguration("Views", env.useCache, env.assemblyName, env.pluginsRelativePath); + const standardConfig: Configuration = getCommonConfiguration("Views", env.useCache, sanitizeCommandLineParam(env.assemblyName), sanitizedPluginsRelativePath); (standardConfig.cache as any).name = "viewsCache"; @@ -55,7 +57,7 @@ const config = (env) => { } }; - generateExtendedConfig(env.pluginsRelativePath || ".", !!env.pluginsRelativePath); + generateExtendedConfig(sanitizedPluginsRelativePath || ".", !!sanitizedPluginsRelativePath); // resolve.alias if (Object.keys(aliasMap).length > 0) {