Skip to content

Commit ca4a46a

Browse files
authored
Merge pull request microsoft#194342 from microsoft/revert-190899-fast-bash-escape-190255
Revert "Faster __vsc_escape_value for bash"
2 parents d1a6d20 + 463d993 commit ca4a46a

File tree

1 file changed

+4
-43
lines changed

1 file changed

+4
-43
lines changed

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fi
4747

4848
# Apply EnvironmentVariableCollections if needed
4949
if [ -n "${VSCODE_ENV_REPLACE:-}" ]; then
50-
IFS=':' read -ra ADDR <<<"$VSCODE_ENV_REPLACE"
50+
IFS=':' read -ra ADDR <<< "$VSCODE_ENV_REPLACE"
5151
for ITEM in "${ADDR[@]}"; do
5252
VARNAME="$(echo $ITEM | cut -d "=" -f 1)"
5353
VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2)"
@@ -56,7 +56,7 @@ if [ -n "${VSCODE_ENV_REPLACE:-}" ]; then
5656
builtin unset VSCODE_ENV_REPLACE
5757
fi
5858
if [ -n "${VSCODE_ENV_PREPEND:-}" ]; then
59-
IFS=':' read -ra ADDR <<<"$VSCODE_ENV_PREPEND"
59+
IFS=':' read -ra ADDR <<< "$VSCODE_ENV_PREPEND"
6060
for ITEM in "${ADDR[@]}"; do
6161
VARNAME="$(echo $ITEM | cut -d "=" -f 1)"
6262
VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2)"
@@ -65,7 +65,7 @@ if [ -n "${VSCODE_ENV_PREPEND:-}" ]; then
6565
builtin unset VSCODE_ENV_PREPEND
6666
fi
6767
if [ -n "${VSCODE_ENV_APPEND:-}" ]; then
68-
IFS=':' read -ra ADDR <<<"$VSCODE_ENV_APPEND"
68+
IFS=':' read -ra ADDR <<< "$VSCODE_ENV_APPEND"
6969
for ITEM in "${ADDR[@]}"; do
7070
VARNAME="$(echo $ITEM | cut -d "=" -f 1)"
7171
VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2)"
@@ -95,52 +95,13 @@ __vsc_get_trap() {
9595
builtin printf '%s' "${terms[2]:-}"
9696
}
9797

98-
__vsc_command_available() {
99-
builtin local trash
100-
trash=$(builtin command -v "$1" 2>&1)
101-
builtin return $?
102-
}
103-
104-
# We provide two faster escaping functions here.
105-
# The first one escapes each byte 0xab into '\xab', which is most scalable and has promising runtime
106-
# efficiency, except that it relies on external commands od and tr.
107-
# The second one is much faster and has zero dependency, except that it escapes only
108-
# '\\' -> '\\\\' and ';' -> '\x3b' and scales up badly when more patterns are needed.
109-
# We default to use the first function if od and tr are available, and fallback to the second otherwise.
110-
if __vsc_command_available od && __vsc_command_available tr; then
111-
__vsc_escape_value_fast() {
112-
builtin local out
113-
# -An removes line number
114-
# -v do not use * to mark line suppression
115-
# -tx1 prints each byte as two-digit hex
116-
# tr -d '\n' concats all output lines
117-
out=$(od -An -vtx1 <<<"$1" | tr -d '\n')
118-
out=${out// /\\x}
119-
# <<<"$1" prepends a trailing newline already, so we don't need to printf '%s\n'
120-
builtin printf '%s' "${out}"
121-
}
122-
else
123-
__vsc_escape_value_fast() {
124-
builtin local LC_ALL=C out
125-
out=${1//\\/\\\\}
126-
out=${out//;/\\x3b}
127-
builtin printf '%s\n' "${out}"
128-
}
129-
fi
130-
13198
# The property (P) and command (E) codes embed values which require escaping.
13299
# Backslashes are doubled. Non-alphanumeric characters are converted to escaped hex.
133100
__vsc_escape_value() {
134-
# If the input being too large, switch to the faster function
135-
if [ "${#1}" -ge 2000 ]; then
136-
__vsc_escape_value_fast "$1"
137-
builtin return
138-
fi
139-
140101
# Process text byte by byte, not by codepoint.
141102
builtin local LC_ALL=C str="${1}" i byte token out=''
142103

143-
for ((i = 0; i < "${#str}"; ++i)); do
104+
for (( i=0; i < "${#str}"; ++i )); do
144105
byte="${str:$i:1}"
145106

146107
# Escape backslashes and semi-colons

0 commit comments

Comments
 (0)