Skip to content

Commit

Permalink
RDEV-5995 Fixed sanitization of command-line parameters (#157)
Browse files Browse the repository at this point in the history
* Revert "RDEV-5995 Fixed quotes in webpack configuration (#156)"

This reverts commit a2121c4.

* RDEV-5995 Fixed sanitization of command-line parameters

* CR
  • Loading branch information
alvesmiguel1 authored Oct 23, 2023
1 parent a2121c4 commit 0934500
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ViewGenerator/ViewGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyTitle>ViewGenerator</AssemblyTitle>
<Product>ViewGenerator</Product>
<Description>Generates .NET View bindings from typescript</Description>
<Version>1.1.12</Version>
<Version>1.1.13</Version>
<PackageId>ViewGenerator</PackageId>
<PackageTags>Library</PackageTags>

Expand Down
6 changes: 3 additions & 3 deletions ViewGenerator/build/ViewGenerator.targets
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,19 @@
<CallTarget Condition="'@(VG_Workers_Inputs)' != ''" Targets="VG_GenerateWorkersBundle" />

<!-- Main bundle generation -->
<Exec Command="node &quot;$(ViewPackerToolScript)&quot; --config='$(ViewGeneratorToolsPath)/webpack/$(WP_ConfigFileName).config.js' --mode=$(WP_Mode) --devtool=$(WP_DevTool) --env useCache=$(WP_UseCache) --env pluginsRelativePath='$(PluginsRelativePath)' --env assemblyName='$(AssemblyName)'" />
<Exec Command="node &quot;$(ViewPackerToolScript)&quot; --config=&quot;$(ViewGeneratorToolsPath)/webpack/$(WP_ConfigFileName).config.js&quot; --mode=$(WP_Mode) --devtool=$(WP_DevTool) --env useCache=$(WP_UseCache) --env pluginsRelativePath='$(PluginsRelativePath)' --env assemblyName='$(AssemblyName)'" />

<Touch Files="VG_Build.cache" AlwaysCreate="true" />
</Target>

<!-- Default stylesheet related target -->
<Target Name="VG_GenerateDefaultStyleSheet" >
<Exec Command="node &quot;$(ViewPackerToolScript)&quot; --config='$(ViewGeneratorToolsPath)/webpack/webpack_stylesheets.config.js' --mode=$(WP_Mode) --devtool=$(WP_DevTool) --env entryPath='@(DefaultStyleSheet)' --env assemblyName='$(AssemblyName)'" />
<Exec Command="node &quot;$(ViewPackerToolScript)&quot; --config=&quot;$(ViewGeneratorToolsPath)/webpack/webpack_stylesheets.config.js&quot; --mode=$(WP_Mode) --devtool=$(WP_DevTool) --env entryPath='@(DefaultStyleSheet)' --env assemblyName='$(AssemblyName)'" />
</Target>

<!-- Workers related target -->
<Target Name="VG_GenerateWorkersBundle" >
<Exec Command="node &quot;$(ViewPackerToolScript)&quot; --config='$(ViewGeneratorToolsPath)/webpack/webpack_workers.config.js' --mode=$(WP_Mode) --devtool=$(WP_DevTool) --env useCache=$(WP_UseCache)" />
<Exec Command="node &quot;$(ViewPackerToolScript)&quot; --config=&quot;$(ViewGeneratorToolsPath)/webpack/webpack_workers.config.js&quot; --mode=$(WP_Mode) --devtool=$(WP_DevTool) --env useCache=$(WP_UseCache)" />
</Target>

<!-- /// -->
Expand Down
16 changes: 12 additions & 4 deletions ViewGenerator/tools/webpack/Plugins/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,21 @@ export function generateManifest(
export function getCurrentDirectory() {
return resolve(".");
}

/*
* Gets the filename from an array.
* */
export function getFileName(relativePaths: Dictionary<string>, chunkData: any) {
const Directory: string = relativePaths[chunkData.chunk.name];
if (Directory) {
return Directory + JsPlaceholder;
export function getFileName(relativePaths: Dictionary<string>, 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("'", "");
}
8 changes: 4 additions & 4 deletions ViewGenerator/tools/webpack/Rules/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion ViewGenerator/tools/webpack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"module": "commonjs",
"target": "es6",
"esModuleInterop": true,
"skipLibCheck": true
"skipLibCheck": true,
"lib": [
"ES2021.String"
]
},
"compileOnSave": true,
"exclude": [
Expand Down
4 changes: 2 additions & 2 deletions ViewGenerator/tools/webpack/webpack_plugins.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
12 changes: 6 additions & 6 deletions ViewGenerator/tools/webpack/webpack_stylesheets.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ 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";

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<string> = {};
entries.split(";").map(entryPath => entryMap[getEntryName(entryPath)] = './' + entryPath)
let stylesheetsConfig: Configuration = {

const stylesheetsConfig: Configuration = {
entry: entryMap,

output: {
Expand All @@ -42,7 +42,7 @@ const config = (env) => {
module: {
rules: [
SassRuleSet,
getResourcesRuleSet(env.assemblyName)
getResourcesRuleSet(sanitizeCommandLineParam(env.assemblyName))
]
},

Expand Down
8 changes: 5 additions & 3 deletions ViewGenerator/tools/webpack/webpack_views.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Expand Down Expand Up @@ -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";

Expand All @@ -55,7 +57,7 @@ const config = (env) => {
}
};

generateExtendedConfig(env.pluginsRelativePath || ".", !!env.pluginsRelativePath);
generateExtendedConfig(sanitizedPluginsRelativePath || ".", !!sanitizedPluginsRelativePath);

// resolve.alias
if (Object.keys(aliasMap).length > 0) {
Expand Down

0 comments on commit 0934500

Please sign in to comment.