Subject: bug#54486: closed (Re: 29.0.50; Eshell `escaped' string property can "leak" into output)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 24 Nov 2024 06:58:01 +0000

Your bug report

#54486: 29.0.50; Eshell `escaped' string property can "leak" into output

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
54486: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54486
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: 29.0.50; Eshell `escaped' string property can "leak" into output
From: Jim Porter <[email-masked]>
To: [email-masked]
Date: Sat, 23 Nov 2024 22:56:54 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

On 3/20/2022 8:52 PM, Jim Porter wrote:
> When using Eshell, it's possible to inadvertently add an `escaped' 
> string property to strings, resulting in some pretty surprising 
> behavior. Starting from "emacs -Q --eval '(eshell)'":
> 
>    ~ $ setq var (list "foo" "bar")
>    ("foo" "bar")
>    ~ $ echo $var
>    ("foo" "bar")
>    ~ $ echo $var[0]
>    foo
>    ~ $ echo $var
>    (#("foo" 0 3
>       (escaped t))
>     "bar")

In the intervening years, I've improved Eshell's parser to prevent other 
bugs, which has resulted in the 'escaped' string property no longer 
being useful.

Instead, Eshell now propertizes text that has actual syntactic meaning: 
for example a globbing character like "*" gets the 'eshell-glob-char' 
text property. By marking *syntactic* characters with a text property, 
we ensure that Eshell only ever adds properties to text literally 
written into the Eshell buffer, which avoids the issue here.

As a result of all this, we can now remove the calls that added that 
property in Eshell. I've now made this change in b4655ff99b5, so closing 
this bug.

Subject: 29.0.50; Eshell `escaped' string property can "leak" into output
From: Jim Porter <[email-masked]>
To: [email-masked]
Date: Sun, 20 Mar 2022 20:52:43 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

When using Eshell, it's possible to inadvertently add an `escaped' 
string property to strings, resulting in some pretty surprising 
behavior. Starting from "emacs -Q --eval '(eshell)'":

   ~ $ setq var (list "foo" "bar")
   ("foo" "bar")
   ~ $ echo $var
   ("foo" "bar")
   ~ $ echo $var[0]
   foo
   ~ $ echo $var
   (#("foo" 0 3
      (escaped t))
    "bar")

This happens because when the `$var[0]' argument is parsed in the third 
command, the function `eshell-interpolate-variable' wraps the 
code-to-be-called with `eshell-escape-arg'. That function adds an 
`escaped' property to any string passed into it.

The `escaped' property is used to indicate that the string should be 
treated literally (i.e. any special characters like "$" will no longer 
have any special meaning in Eshell). That's the right *behavior*, but 
ideally, there'd be a way to do so that doesn't involve manipulating the 
string like this. Eshell can't know the lifetime of the string, and it 
seems like a bad idea in general to go around messing with string 
properties just because you referenced that string somehow in Eshell.

I can't think of an obvious fix for this though. Any ideas?