From 0749d65173e8cfe9a93464711b7be1e123c289ff Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 19 Sep 2022 15:53:51 +0500 Subject: [PATCH 1/3] fix: SASJS_WEBOUT_HEADERS path for windows --- api/src/controllers/internal/createJSProgram.ts | 4 +++- api/src/controllers/internal/createPythonProgram.ts | 4 +++- api/src/controllers/internal/createRProgram.ts | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/src/controllers/internal/createJSProgram.ts b/api/src/controllers/internal/createJSProgram.ts index 2a7d5949..dcea6b86 100644 --- a/api/src/controllers/internal/createJSProgram.ts +++ b/api/src/controllers/internal/createJSProgram.ts @@ -27,7 +27,9 @@ const weboutPath = '${ const _SASJS_TOKENFILE = '${ isWindows() ? tokenFile.replace(/\\/g, '\\\\') : tokenFile }'; -const _SASJS_WEBOUT_HEADERS = '${headersPath}'; +const _SASJS_WEBOUT_HEADERS = '${ + isWindows() ? headersPath.replace(/\\/g, '\\\\') : 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 d33231c6..f71f5d51 100644 --- a/api/src/controllers/internal/createPythonProgram.ts +++ b/api/src/controllers/internal/createPythonProgram.ts @@ -23,7 +23,9 @@ _SASJS_SESSION_PATH = '${ isWindows() ? session.path.replace(/\\/g, '\\\\') : session.path }'; _WEBOUT = '${isWindows() ? weboutPath.replace(/\\/g, '\\\\') : weboutPath}'; -_SASJS_WEBOUT_HEADERS = '${headersPath}'; +_SASJS_WEBOUT_HEADERS = '${ + isWindows() ? headersPath.replace(/\\/g, '\\\\') : headersPath + }'; _SASJS_TOKENFILE = '${ isWindows() ? tokenFile.replace(/\\/g, '\\\\') : tokenFile }'; diff --git a/api/src/controllers/internal/createRProgram.ts b/api/src/controllers/internal/createRProgram.ts index 33af81c5..e7b4a808 100644 --- a/api/src/controllers/internal/createRProgram.ts +++ b/api/src/controllers/internal/createRProgram.ts @@ -23,7 +23,9 @@ export const createRProgram = async ( isWindows() ? session.path.replace(/\\/g, '\\\\') : session.path }'; ._WEBOUT <- '${isWindows() ? weboutPath.replace(/\\/g, '\\\\') : weboutPath}'; -._SASJS_WEBOUT_HEADERS <- '${headersPath}'; +._SASJS_WEBOUT_HEADERS <- '${ + isWindows() ? headersPath.replace(/\\/g, '\\\\') : headersPath + }'; ._SASJS_TOKENFILE <- '${ isWindows() ? tokenFile.replace(/\\/g, '\\\\') : tokenFile }'; From 92549402eb19478698d1f71d95d80493eee9692d Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 19 Sep 2022 23:36:04 +0500 Subject: [PATCH 2/3] 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 72dbb82e..592a2881 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 75d5770c..ea5b9ffb 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 dcea6b86..15c035a6 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 f71f5d51..3b5d4985 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 e7b4a808..a10dbe8b 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 b1745dba..bd36ade8 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 cd7966c3..ca4a9d44 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 ) From 0327f7c6ec510e652b56ddea867e2ebb25fe0757 Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 19 Sep 2022 23:51:18 +0500 Subject: [PATCH 3/3] chore: no need to escapeWinSlash in _sasjs_webout_headers --- api/src/controllers/internal/createSASProgram.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/controllers/internal/createSASProgram.ts b/api/src/controllers/internal/createSASProgram.ts index bd36ade8..e86e41c2 100644 --- a/api/src/controllers/internal/createSASProgram.ts +++ b/api/src/controllers/internal/createSASProgram.ts @@ -1,4 +1,3 @@ -import { escapeWinSlashes } from '@sasjs/utils' import { PreProgramVars, Session } from '../../types' import { generateFileUploadSasCode, getMacrosFolder } from '../../utils' import { ExecutionVars } from './' @@ -25,7 +24,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=${escapeWinSlashes(headersPath)}; +%let _sasjs_webout_headers=${headersPath}; %let _metaperson=&_sasjs_displayname; %let _metauser=&_sasjs_username;