Skip to content

Commit

Permalink
Dollar sign care
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Zeithaml <[email protected]>
  • Loading branch information
Martin-Zeithaml committed Nov 8, 2023
1 parent cde40d7 commit 1cc069f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion bin/libs/configmgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as os from 'cm_os';
import * as xplatform from 'xplatform';
import { ConfigManager } from 'Configuration';
import * as fs from './fs';
import * as stringlib from './string';

import * as objUtils from '../utils/ObjUtils';

Expand Down Expand Up @@ -413,7 +414,8 @@ function getMemberNameFromConfigPath(configPath: string): string|undefined {
function stripMemberName(configPath: string, memberName: string): string {
//Turn PARMLIB(my.zowe(yaml)):PARMLIB(my.other.zowe(yaml))
//Into PARMLIB(my.zowe):FILE(/some/path.yaml):PARMLIB(my.other.zowe)
const replacer = new RegExp('\\('+memberName+'\\)\\)', 'gi');
//$ is valid char for member name, escape it for RegExp
const replacer = new RegExp('\\('+stringlib.escapeRegExp(memberName)+'\\)\\)', 'gi');
return configPath.replace(replacer, ")");
}

Expand Down
12 changes: 12 additions & 0 deletions bin/libs/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ export function trim(input: string): string {
return input.trim();
}

export function escapeDollar(str: string): string | undefined {
if (str === null || str === undefined)
return undefined;
return str.replace(/[$]/g, '\\$&');
}

export function escapeRegExp(str: string): string | undefined {
if (str === null || str === undefined)
return undefined;
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

// Replace all occurrences of a string with another
export function replace(sourceString: string, searchTerm: string, replaceTerm: string): string {
const all = new RegExp(searchTerm, 'g')
Expand Down
16 changes: 8 additions & 8 deletions bin/libs/zos-dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as shell from './shell';
import * as zoslib from './zos';

export function isDatasetExists(datasetName: string): boolean {
const result = shell.execSync('sh', '-c', `cat "//'${datasetName}'" 1>/dev/null 2>&1`);
const result = shell.execSync('sh', '-c', `cat "//'${stringlib.escapeDollar(datasetName)}'" 1>/dev/null 2>&1`);
return result.rc === 0;
}

Expand All @@ -27,7 +27,7 @@ export function isDatasetExists(datasetName: string): boolean {
// 1: data set is not in catalog
// 2: data set member doesn't exist
export function tsoIsDatasetExists(datasetName: string): number {
const result = zoslib.tsoCommand(`listds '${datasetName}' label`);
const result = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(datasetName)}' label`);
if (result.rc != 0) {
if (result.out.includes('NOT IN CATALOG')) {
return 1;
Expand All @@ -44,7 +44,7 @@ export function tsoIsDatasetExists(datasetName: string): number {
}

export function createDataSet(dsName: string, dsOptions: string): number {
const result=zoslib.tsoCommand(`ALLOCATE NEW DA('${dsName}') ${dsOptions}`);
const result=zoslib.tsoCommand(`ALLOCATE NEW DA('${stringlib.escapeDollar(dsName)}') ${dsOptions}`);
return result.rc;
}

Expand All @@ -55,7 +55,7 @@ export function copyToDataset(filePath: string, dsName: string, cpOptions: strin
}
}

const cpCommand=`cp ${cpOptions} -v "${filePath}" "//'${dsName}'"`;
const cpCommand=`cp ${cpOptions} -v "${filePath}" "//'${stringlib.escapeDollar(dsName)}'"`;
common.printDebug('- '+cpCommand);
const result=shell.execOutSync('sh', '-c', `${cpCommand} 2>&1`);
if (result.rc == 0) {
Expand All @@ -79,7 +79,7 @@ export function datasetCopyToDataset(prefix: string, datasetFrom: string, datase
}
}

const cmd=`exec '${prefix}.${std.getenv('ZWE_PRIVATE_DS_SZWEEXEC')}(ZWEMCOPY)' '${datasetFrom} ${datasetTo}'`;
const cmd=`exec '${prefix}.${std.getenv('ZWE_PRIVATE_DS_SZWEEXEC')}(ZWEMCOPY)' '${stringlib.escapeDollar(datasetFrom)} ${stringlib.escapeDollar(datasetTo)}'`;
const result = zoslib.tsoCommand(cmd);
return result.rc;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ export function listDatasetUser(datasetName: string): number {
// 3: data set is in use
// @output tso listds label output
export function deleteDataset(dataset: string): number {
const cmd=`delete '${dataset}'`;
const cmd=`delete '${stringlib.escapeDollar(dataset)}'`;
const result=zoslib.tsoCommand(cmd);
if (result.rc != 0) {
if (result.out.includes('NOT IN CATALOG')) {
Expand Down Expand Up @@ -170,7 +170,7 @@ export function isDatasetSmsManaged(dataset: string): { rc: number, smsManaged?:
// SMS flag is in `FORMAT 1 DSCB` section second line, after 780037

common.printTrace(`- Check if ${dataset} is SMS managed`);
const labelResult = zoslib.tsoCommand(`listds '${dataset}' label`);
const labelResult = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(dataset)}' label`);
const datasetLabel=labelResult.out;
if (labelResult.rc == 0) {
let formatIndex = datasetLabel.indexOf('--FORMAT 1 DSCB--');
Expand Down Expand Up @@ -212,7 +212,7 @@ export function isDatasetSmsManaged(dataset: string): { rc: number, smsManaged?:

export function getDatasetVolume(dataset: string): { rc: number, volume?: string } {
common.printTrace(`- Find volume of data set ${dataset}`);
const result = zoslib.tsoCommand(`listds '${dataset}'`);
const result = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(dataset)}'`);
if (result.rc == 0) {
let volumesIndex = result.out.indexOf('--VOLUMES--');
let volume: string;
Expand Down

0 comments on commit 1cc069f

Please sign in to comment.