Skip to content

Commit 50d59d7

Browse files
committed
shellIntegration.fish: fully implement the value escaping
1 parent f80346a commit 50d59d7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/vs/workbench/contrib/terminal/browser/media/shellIntegration.fish

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,25 @@ end
3939

4040

4141
# Escape a value for use in the 'P' ("Property") or 'E' ("Command Line") sequences.
42+
# Backslashes are doubled and non-alphanumeric characters are hex encoded.
4243
function __vsc_escape_value
43-
set -l commandline "$argv"
44-
# `string replace` automatically breaks its input apart on any newlines.
45-
# Then `string join` at the end will bring it all back together.
46-
string replace --all '\\' '\\\\' $commandline \
47-
| string replace --all ';' '\\x3b' \
48-
| string join '\\x0a'
44+
# Replace all non-alnum characters with %XX hex form.
45+
string escape --style=url "$argv" \
46+
# The characters [-./_~] are not encoded in the builtin url escaping, despite not being alphanumeric.
47+
# See: https://github.com/fish-shell/fish-shell/blob/f82537bcdcb32f85a530395f00e7be1aa9afc592/src/common.cpp#L738
48+
# For consistency, also encode those characters.
49+
| string replace --all '-' '%2D' \
50+
| string replace --all '.' '%2E' \
51+
| string replace --all '/' '%2F' \
52+
| string replace --all '_' '%5F' \
53+
| string replace --all '~' '%7E' \
54+
# Now everything is either alphanumeric [0-9A-Za-z] or %XX escapes.
55+
# Change the hex escape representation from '%' to '\x'. (e.g. ' ' → '%20' → '\x20').
56+
# Note that all '%' characters are escapes: literal '%' will already have been encoded.
57+
| string replace --all '%' '\\x' \
58+
# For readability, prefer to represent literal backslashes with doubling. ('\' → '%5C' → '\x5C' → '\\').
59+
| string replace --all --ignore-case '%5C' '\\\\' \
60+
;
4961
end
5062
5163
# Sent right after an interactive command has finished executing.

0 commit comments

Comments
 (0)