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

fix for #906, 1) windows paths like C:\a\b weren't accepted because b… #935

Merged
merged 4 commits into from
Nov 20, 2018

Conversation

moltenform
Copy link
Contributor

  1. windows paths like C:\a\b weren't accepted because backslashes were treated as escape sequences,
  2. common paths like C:\Program Files\Foo\Foo.exe weren't accepted because of the space in the path

…because backslashes were treated as escape sequences, 2) common paths like C:\Program Files\Foo\Foo.exe weren't accepted because of the space in the path
@laurent22
Copy link
Owner

Thanks for the patch. Do you know what part of the code was treating "" as an escape character? Maybe, rather than escaping the path, whatever was incorrectly treating \ as escape character should be fixed?

@moltenform
Copy link
Contributor Author

It's splitCommandString() that is both treating \ as an escape character and treating spaces as separating arguments. This is right for Linux, where paths don't usually have spaces, but isn't expected in Windows.

True, a simpler approach could be to simply skip splitCommandString() on Windows and pass the string as one argument. I doubt that Windows users would need to pass flags to a .exe. This would be a simpler ~5 line patch, along with a new string, since the documentation string says "The editor command (may include arguments) that will be used..." would have a Windows version that says "The editor command that will be used..."

If that would be preferred, I'll update the pr.

@laurent22
Copy link
Owner

It's splitCommandString() that is both treating \ as an escape character and treating spaces as separating arguments. This is right for Linux, where paths don't usually have spaces, but isn't expected in Windows.

Hmm, yes I think the bug is indeed in splitCommandString(). I've converted this function from some of my Golang code but it was used in a different context where escaping needed to be supported. However in this case we don't ever need escaping - the app should just take whatever string the user provided and run this.

So yes I think if you could fix this function by making its ability to escape option it should be fine. Like the signature would be this:

function splitCommandString(command, options =null) {
    options = {...options};
    if (!('handleEscape' in options)) options.handleEscape = true;
    /// etc.
}

For the spaces in Windows, the splitCommandString function supports quotes around paths so we don't need to do something special for this. Perhaps we could add a description below the field though - something like "If you path contains spaces, add double quotes around it".

@moltenform
Copy link
Contributor Author

When I update joplin.pot, which script should I run to regenerate locales/*.js ? (I'm guessing something related to gettext)

@laurent22
Copy link
Owner

You don't need to regenerate the .pot file, I take care of it when I rebuild all the translations. If you want a string to be translated, simply wrap it in _().

Ben Fisher added 2 commits November 8, 2018 12:37
a) backslashes are no longer treated as escape characters,
b) string change to remind people to add spaces
}

// in windows, \ usually is a path delim, not an escape sequence
cmd = cmd.replace(/\\/g, '\\\\');
Copy link
Owner

Choose a reason for hiding this comment

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

Is there any reason we still need this, since in splitCommandString you are now disabling escape?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good catch.

@laurent22
Copy link
Owner

Sorry I missed your new commits from a few days ago. I think it's almost ready to merge but I just have one question on one of the changes. If you could just confirm on this that would be great.

@moltenform
Copy link
Contributor Author

Sounds good.

@laurent22
Copy link
Owner

Thanks @downpoured!

@laurent22 laurent22 merged commit 58b68ca into laurent22:master Nov 20, 2018
@moltenform
Copy link
Contributor Author

Thanks!

By the way, I'm thinking of changing my username on here to 'moltenjs' within the next few days, GitHub seems to handle this fine, but letting you know just in case.

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.

2 participants