From 92549402eb19478698d1f71d95d80493eee9692d Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 19 Sep 2022 23:36:04 +0500 Subject: [PATCH] chore: use utility function escapeWinSlashes --- api/package-lock.json | 14 +++++++------- api/package.json | 2 +- api/src/controllers/internal/createJSProgram.ts | 14 ++++---------- .../controllers/internal/createPythonProgram.ts | 16 +++++----------- api/src/controllers/internal/createRProgram.ts | 16 +++++----------- api/src/controllers/internal/createSASProgram.ts | 4 +++- api/src/controllers/internal/processProgram.ts | 1 + 7 files changed, 26 insertions(+), 41 deletions(-) diff --git a/api/package-lock.json b/api/package-lock.json index 72dbb82..592a288 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.2", "dependencies": { "@sasjs/core": "^4.31.3", - "@sasjs/utils": "2.42.1", + "@sasjs/utils": "2.48.1", "bcryptjs": "^2.4.3", "connect-mongo": "^4.6.0", "cookie-parser": "^1.4.6", @@ -1396,9 +1396,9 @@ "integrity": "sha512-TpVqWl5bqp3JTQjIg0r4WiQg7Ima5f17eAJILJbdYDdXsnLXlA/Csbb95G7eDPhzWpM3C0NrzKek3yvCMGzXIA==" }, "node_modules/@sasjs/utils": { - "version": "2.42.1", - "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.1.tgz", - "integrity": "sha512-DzHNYjeoj2eUkwV7Sa4eHCKRoTrYaQ6eyv6c1U5qOYXwVdZpMoYA3HFsHj55UcMOn2U3CXI5nrR7PZlUmVwVbQ==", + "version": "2.48.1", + "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.48.1.tgz", + "integrity": "sha512-Eu9p66JKLeTj0KK3kfY7YLQYq+MDMS1Q1/FOFfRe9hV23mFsuzierVMrnEYGK0JaHOogdHLmwzg6iVLDT8Jssg==", "hasInstallScript": true, "dependencies": { "@types/fs-extra": "9.0.13", @@ -10974,9 +10974,9 @@ "integrity": "sha512-TpVqWl5bqp3JTQjIg0r4WiQg7Ima5f17eAJILJbdYDdXsnLXlA/Csbb95G7eDPhzWpM3C0NrzKek3yvCMGzXIA==" }, "@sasjs/utils": { - "version": "2.42.1", - "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.1.tgz", - "integrity": "sha512-DzHNYjeoj2eUkwV7Sa4eHCKRoTrYaQ6eyv6c1U5qOYXwVdZpMoYA3HFsHj55UcMOn2U3CXI5nrR7PZlUmVwVbQ==", + "version": "2.48.1", + "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.48.1.tgz", + "integrity": "sha512-Eu9p66JKLeTj0KK3kfY7YLQYq+MDMS1Q1/FOFfRe9hV23mFsuzierVMrnEYGK0JaHOogdHLmwzg6iVLDT8Jssg==", "requires": { "@types/fs-extra": "9.0.13", "@types/prompts": "2.0.13", diff --git a/api/package.json b/api/package.json index 75d5770..ea5b9ff 100644 --- a/api/package.json +++ b/api/package.json @@ -48,7 +48,7 @@ "author": "4GL Ltd", "dependencies": { "@sasjs/core": "^4.31.3", - "@sasjs/utils": "2.42.1", + "@sasjs/utils": "2.48.1", "bcryptjs": "^2.4.3", "connect-mongo": "^4.6.0", "cookie-parser": "^1.4.6", diff --git a/api/src/controllers/internal/createJSProgram.ts b/api/src/controllers/internal/createJSProgram.ts index dcea6b8..15c035a 100644 --- a/api/src/controllers/internal/createJSProgram.ts +++ b/api/src/controllers/internal/createJSProgram.ts @@ -1,4 +1,4 @@ -import { isWindows } from '@sasjs/utils' +import { escapeWinSlashes } from '@sasjs/utils' import { PreProgramVars, Session } from '../../types' import { generateFileUploadJSCode } from '../../utils' import { ExecutionVars } from './' @@ -21,15 +21,9 @@ export const createJSProgram = async ( const preProgramVarStatments = ` let _webout = ''; -const weboutPath = '${ - isWindows() ? weboutPath.replace(/\\/g, '\\\\') : weboutPath - }'; -const _SASJS_TOKENFILE = '${ - isWindows() ? tokenFile.replace(/\\/g, '\\\\') : tokenFile - }'; -const _SASJS_WEBOUT_HEADERS = '${ - isWindows() ? headersPath.replace(/\\/g, '\\\\') : headersPath - }'; +const weboutPath = '${escapeWinSlashes(weboutPath)}'; +const _SASJS_TOKENFILE = '${escapeWinSlashes(tokenFile)}'; +const _SASJS_WEBOUT_HEADERS = '${escapeWinSlashes(headersPath)}'; const _SASJS_USERNAME = '${preProgramVariables?.username}'; const _SASJS_USERID = '${preProgramVariables?.userId}'; const _SASJS_DISPLAYNAME = '${preProgramVariables?.displayName}'; diff --git a/api/src/controllers/internal/createPythonProgram.ts b/api/src/controllers/internal/createPythonProgram.ts index f71f5d5..3b5d498 100644 --- a/api/src/controllers/internal/createPythonProgram.ts +++ b/api/src/controllers/internal/createPythonProgram.ts @@ -1,4 +1,4 @@ -import { isWindows } from '@sasjs/utils' +import { escapeWinSlashes } from '@sasjs/utils' import { PreProgramVars, Session } from '../../types' import { generateFileUploadPythonCode } from '../../utils' import { ExecutionVars } from './' @@ -19,16 +19,10 @@ export const createPythonProgram = async ( ) const preProgramVarStatments = ` -_SASJS_SESSION_PATH = '${ - isWindows() ? session.path.replace(/\\/g, '\\\\') : session.path - }'; -_WEBOUT = '${isWindows() ? weboutPath.replace(/\\/g, '\\\\') : weboutPath}'; -_SASJS_WEBOUT_HEADERS = '${ - isWindows() ? headersPath.replace(/\\/g, '\\\\') : headersPath - }'; -_SASJS_TOKENFILE = '${ - isWindows() ? tokenFile.replace(/\\/g, '\\\\') : tokenFile - }'; +_SASJS_SESSION_PATH = '${escapeWinSlashes(session.path)}'; +_WEBOUT = '${escapeWinSlashes(weboutPath)}'; +_SASJS_WEBOUT_HEADERS = '${escapeWinSlashes(headersPath)}'; +_SASJS_TOKENFILE = '${escapeWinSlashes(tokenFile)}'; _SASJS_USERNAME = '${preProgramVariables?.username}'; _SASJS_USERID = '${preProgramVariables?.userId}'; _SASJS_DISPLAYNAME = '${preProgramVariables?.displayName}'; diff --git a/api/src/controllers/internal/createRProgram.ts b/api/src/controllers/internal/createRProgram.ts index e7b4a80..a10dbe8 100644 --- a/api/src/controllers/internal/createRProgram.ts +++ b/api/src/controllers/internal/createRProgram.ts @@ -1,4 +1,4 @@ -import { isWindows } from '@sasjs/utils' +import { escapeWinSlashes } from '@sasjs/utils' import { PreProgramVars, Session } from '../../types' import { generateFileUploadRCode } from '../../utils' import { ExecutionVars } from '.' @@ -19,16 +19,10 @@ export const createRProgram = async ( ) const preProgramVarStatments = ` -._SASJS_SESSION_PATH <- '${ - isWindows() ? session.path.replace(/\\/g, '\\\\') : session.path - }'; -._WEBOUT <- '${isWindows() ? weboutPath.replace(/\\/g, '\\\\') : weboutPath}'; -._SASJS_WEBOUT_HEADERS <- '${ - isWindows() ? headersPath.replace(/\\/g, '\\\\') : headersPath - }'; -._SASJS_TOKENFILE <- '${ - isWindows() ? tokenFile.replace(/\\/g, '\\\\') : tokenFile - }'; +._SASJS_SESSION_PATH <- '${escapeWinSlashes(session.path)}'; +._WEBOUT <- '${escapeWinSlashes(weboutPath)}'; +._SASJS_WEBOUT_HEADERS <- '${escapeWinSlashes(headersPath)}'; +._SASJS_TOKENFILE <- '${escapeWinSlashes(tokenFile)}'; ._SASJS_USERNAME <- '${preProgramVariables?.username}'; ._SASJS_USERID <- '${preProgramVariables?.userId}'; ._SASJS_DISPLAYNAME <- '${preProgramVariables?.displayName}'; diff --git a/api/src/controllers/internal/createSASProgram.ts b/api/src/controllers/internal/createSASProgram.ts index b1745db..bd36ade 100644 --- a/api/src/controllers/internal/createSASProgram.ts +++ b/api/src/controllers/internal/createSASProgram.ts @@ -1,3 +1,4 @@ +import { escapeWinSlashes } from '@sasjs/utils' import { PreProgramVars, Session } from '../../types' import { generateFileUploadSasCode, getMacrosFolder } from '../../utils' import { ExecutionVars } from './' @@ -8,6 +9,7 @@ export const createSASProgram = async ( vars: ExecutionVars, session: Session, weboutPath: string, + headersPath: string, tokenFile: string, otherArgs?: any ) => { @@ -23,7 +25,7 @@ export const createSASProgram = async ( %let _sasjs_displayname=${preProgramVariables?.displayName}; %let _sasjs_apiserverurl=${preProgramVariables?.serverUrl}; %let _sasjs_apipath=/SASjsApi/stp/execute; -%let _sasjs_webout_headers=%sysfunc(pathname(work))/../stpsrv_header.txt; +%let _sasjs_webout_headers=${escapeWinSlashes(headersPath)}; %let _metaperson=&_sasjs_displayname; %let _metauser=&_sasjs_username; diff --git a/api/src/controllers/internal/processProgram.ts b/api/src/controllers/internal/processProgram.ts index cd7966c..ca4a9d4 100644 --- a/api/src/controllers/internal/processProgram.ts +++ b/api/src/controllers/internal/processProgram.ts @@ -32,6 +32,7 @@ export const processProgram = async ( vars, session, weboutPath, + headersPath, tokenFile, otherArgs )