diff options
author | Sebastian Larsson <sjereq@gmail.com> | 2017-04-30 14:40:04 +0200 |
---|---|---|
committer | Sebastian Larsson <sjereq@gmail.com> | 2017-04-30 14:40:04 +0200 |
commit | 32175b0a1f2db722a0adc149f1ddc3cbef1f9553 (patch) | |
tree | 2fb331dc3e62181b472946c625f02aa69013d627 /i3-dmenu-desktop | |
parent | 1d4e9f5de0281d4f152420a90edc59577e142221 (diff) | |
download | i3-32175b0a1f2db722a0adc149f1ddc3cbef1f9553.tar.gz i3-32175b0a1f2db722a0adc149f1ddc3cbef1f9553.zip |
Fix i3-dmenu-desktop quoted command name
According to the Desktop Entry Specification
https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables
the executable name or path of the executable may be quoted. This is not
properly respected when i3-dmenu-desktop extracts the command name from
the Exec entry.
Examples of values that fail and what they currently result in:
- "bar" -> "bar"
- "foo/bar" -> bar"
- "foo foobar/bar" -> "foo
- "foo\sbar" -> "foo\sbar"
- foo\sbar -> foo\sbar
- "foo\\\\bar" -> "foo\\\\bar"
Diffstat (limited to 'i3-dmenu-desktop')
-rwxr-xr-x | i3-dmenu-desktop | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/i3-dmenu-desktop b/i3-dmenu-desktop index 3b81cb20..1d29a69f 100755 --- a/i3-dmenu-desktop +++ b/i3-dmenu-desktop @@ -282,7 +282,31 @@ for my $app (keys %apps) { } if ((scalar grep { $_ eq 'command' } @entry_types) > 0) { - my ($command) = split(' ', $apps{$app}->{Exec}); + my $command = $apps{$app}->{Exec}; + + # Handle escape sequences (should be done for all string values, but does + # matter here). + my %escapes = ( + '\\s' => ' ', + '\\n' => '\n', + '\\t' => '\t', + '\\r' => '\r', + '\\\\' => '\\', + ); + $command =~ s/(\\[sntr\\])/$escapes{$1}/go; + + # Extract executable + if ($command =~ m/^\s*([^\s\"]+)(?:\s|$)/) { + # No quotes + $command = $1; + } elsif ($command =~ m/^\s*\"([^\"\\]*(?:\\.[^\"\\]*)*)\"(?:\s|$)/) { + # Quoted, remove quotes and fix escaped characters + $command = $1; + $command =~ s/\\([\"\`\$\\])/$1/g; + } else { + # Invalid quotes, fallback to whitespace + ($command) = split(' ', $command); + } # Don’t add “geany” if “Geany” is already present. my @keys = map { lc } keys %choices; |