Don't escape '#' in some cases where it's not necessary

This is useful for the next commit where tab completion produces
tokens like "foo#bar". Some cases are missing though, because we
still need to tell this function what's the previous character.
I guess next commit could also use a different sigil.
This commit is contained in:
Johannes Altmanninger
2025-11-05 13:44:42 +01:00
parent cc95cef165
commit 2c68a6704f
2 changed files with 11 additions and 3 deletions

View File

@@ -204,7 +204,7 @@ fn escape_string_script(input: &wstr, flags: EscapeFlags) -> WString {
let mut out = WString::new(); let mut out = WString::new();
for c in input.chars() { for (i, c) in input.chars().enumerate() {
if let Some(val) = decode_byte_from_char(c) { if let Some(val) = decode_byte_from_char(c) {
out += "\\X"; out += "\\X";
@@ -308,7 +308,12 @@ fn escape_string_script(input: &wstr, flags: EscapeFlags) -> WString {
if c == '$' { if c == '$' {
dollars += 1; dollars += 1;
} }
let char_is_normal = (c == '~' && no_tilde) || (c == '?' && no_qmark); let char_is_normal = (c == '~' && no_tilde)
|| (c == '?' && no_qmark)
|| (c == '#'
&& i.checked_sub(1)
.map(|previ| input.char_at(previ).is_alphanumeric())
.unwrap_or_default());
if !char_is_normal { if !char_is_normal {
need_escape = true; need_escape = true;
if escape_printables { if escape_printables {

View File

@@ -305,7 +305,10 @@ string escape --style=script 'a b#c"\'d'
# CHECK: 'a b#c"\'d' # CHECK: 'a b#c"\'d'
string escape --no-quoted --style=script 'a b#c"\'d' string escape --no-quoted --style=script 'a b#c"\'d'
# CHECK: a\ b\#c\"\'d # CHECK: a\ b#c\"\'d
string escape --no-quoted --style=script 'a #b'
# CHECK: a\ \#b
string escape --style=url 'a b#c"\'d' string escape --style=url 'a b#c"\'d'
# CHECK: a%20b%23c%22%27d # CHECK: a%20b%23c%22%27d