Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdfix #45

Merged
merged 11 commits into from
Dec 15, 2023
Merged

Sdfix #45

merged 11 commits into from
Dec 15, 2023

Conversation

sameagen-MW
Copy link
Contributor

@sameagen-MW sameagen-MW commented Dec 14, 2023

Fix for the -sd option using an environment variable. Because it changes the function signature of cdAndCall, run-build and run-tests will need to be updated in parallel.

EDIT: Even better it looks like I remembered incorrectly and the other two actions don't directly call cdAndCall

src/matlab.ts Outdated
@@ -54,7 +54,7 @@ export async function runCommand(hs: HelperScript, platform: string, architectur
const rmcPath = getRunMATLABCommandScriptPath(platform, architecture);
await fs.chmod(rmcPath, 0o777);

const rmcArg = script.cdAndCall(hs.dir, hs.command);
const rmcArg = `setenv("MW_ORIG_WORKING_FOLDER", cd('${hs.dir}'));${hs.command}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safest to use ' instead of " to support MATLAB releases as far back as possible.

Also probably a good idea to escape any ' chars in hs.dir.

src/script.ts Outdated
export function cdAndCall(dir: string, command: string): string {
return `cd('${pathToCharVec(dir)}');${command}`;
export function cdAndCall(command: string): string {
return `cd(getenv("MW_ORIG_WORKING_FOLDER"));${command}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" -> '

const testCommand = "disp('hello world')";
const expectedString = String.raw`cd('C:\Users\you\You''re Documents');${testCommand}`;
const expectedString = `cd(getenv("MW_ORIG_WORKING_FOLDER"));${testCommand}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" -> '

src/matlab.ts Outdated
@@ -54,7 +57,7 @@ export async function runCommand(hs: HelperScript, platform: string, architectur
const rmcPath = getRunMATLABCommandScriptPath(platform, architecture);
await fs.chmod(rmcPath, 0o777);

const rmcArg = script.cdAndCall(hs.dir, hs.command);
const rmcArg = `setenv('MW_ORIG_WORKING_FOLDER', cd('${hs.dir}'));${hs.command}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to escape 's here right before injecting it into the char array. Then all users of this function don't need to know they need to escape the dir before calling this function and the need to escape is implementation detail of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that mean that the other function consumers would likely have to escape the dir themselves later on? I can't think of many cases where someone would be calling generateScript and not wanting the directory to be escaped but i'm probably missing something

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateScript just generates a script and returns the directory that script lives in. It shouldn't assume you're then going to inject that directory path into a MATLAB char array later on. If, for instance, you wanted to delete that directory from JavaScript code, you've got an issue because the directory path is wrong.

Copy link
Contributor

@davidbuzinski davidbuzinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@sameagen-MW sameagen-MW merged commit 07310e1 into main Dec 15, 2023
1 check passed
@sameagen-MW sameagen-MW deleted the sdfix branch December 15, 2023 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants