Taitava / obsidian-shellcommands

Execute system commands via hotkeys or command palette in Obsidian (https://obsidian.md). Some automated events are also supported, and execution via URI links.
GNU General Public License v3.0
351 stars 11 forks source link

Dollar sign in variable value may cause part of the command to be repeated in the variable value #94

Closed Taitava closed 2 years ago

Taitava commented 2 years ago

Problematic symbol pairs

If a {{variable}} gives a value that contains one of the following...:

Only in variable values

I need to epmhasize that this bug occurs when one of the above symbol pairs occurs in a value returned by a variable. E.g. if you have $& in your clipboard and you use a shell command like echo {{clipboard}}, the bug will happen. However, if your clipboard doesn't contain $&, but your shell command does have it outside of a variable, e.g. echo "$&" {{cliboard}}, then the bug will not happen, because $& will not be part of variable parsing.

An example command to demonstrate the problem

a) Say that you have the following:

b) Say that you have the following:

The latter is even more dangerous as it has theoretical risk of repeating a command (echo in this case, which is not so dangerous, but some other command might be). Here's a screenshot of the latter example: kuva (SC version 0.6.0)

Affected versions

I've tested this in 0.6.0 and the still in-development 0.7.0 and the bug happens on both of them. I have all reasons to think that this bug affects all versions of SC that support variables, which mean all versions between 0.1.0 - 0.6.0.

0.7.0 will have a fix for this, but I'll also release a patch version 0.6.1 just for this fix. 0.6.1 will be released sooner than 0.7.0.

Taitava commented 2 years ago

Here is the cause of the bug: https://github.com/Taitava/obsidian-shellcommands/blob/83504bc250025a89c93665201caf48865ddd01f3/src/variables/parseShellCommandVariables.ts#L70 Here .replace() applies the above list of things to variable_value. I need to replace variable_value with a function that returns variable_value. Kind of foolish, but it prevents JavaScript from doing this kind of replacing.