Skip to content

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
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 testDir = String.raw`C:\Users\you\You're Documents`;
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
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
@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.

5 participants