mbox series

[0/2] data: Escape back quotes in environment

Message ID 20251114-mathieu-back_quote_devshell-v1-0-45e83df2f362@bootlin.com
Headers show
Series data: Escape back quotes in environment | expand

Message

Mathieu Dubois-Briand Nov. 14, 2025, 1:27 p.m. UTC
Fixing devshell when some environment variables contain a back quote. On
my side I had this issue using kitty terminal emulator, which sets the
KITTY_PUBLIC_KEY environment variable [1]:
KITTY_PUBLIC_KEY=1:`TB}~6^vgiFD2v6d}JRgt!X|qx#0~mO?&N=A1jfi

Trying to use devshell failed silently, but the parse error is visible
while launching the do_terminal script by hand:

tmp/work/qemux86_64-poky-linux/linux-yocto/6.16.11+git/temp/run.do_terminal.2972397: line 120: unexpected EOF while looking for matching ``'
WARNING: tmp/work/qemux86_64-poky-linux/linux-yocto/6.16.11+git/temp/run.do_terminal.2972397:119 exit 2 from 'export KITTY_PID="1985830"'
WARNING: Backtrace (BB generated script): 
	#1: main, tmp/work/qemux86_64-poky-linux/linux-yocto/6.16.11+git/temp/run.do_terminal.2972397, line 119

Escaping back quotes allows to launch the devshell correctly.

Also adding a non-regression test. The whole bb.data.emit_var() function
was not tested, I'm not sure if it was by choice or not, but I added
some.

I tested the most basic code paths of bb.data.emit_var() but I'm not
fully exhaustive. Notably, the return value remains untested as I was
not able to figure out what it means and it appears to be unused.

[1]: https://sw.kovidgoyal.net/kitty/glossary/#envvar-KITTY_PUBLIC_KEY

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
Mathieu Dubois-Briand (2):
      data: Escape back quotes in environment
      tests: data: Add tests on emitting environment variables

 lib/bb/data.py       |   1 +
 lib/bb/tests/data.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
---
base-commit: ce90d59ff1c96d04856ca5e41a963af00d1783f1
change-id: 20251114-mathieu-back_quote_devshell-b1b19d3c4042

Best regards,

Comments

Richard Purdie Nov. 14, 2025, 4:20 p.m. UTC | #1
On Fri, 2025-11-14 at 14:27 +0100, Mathieu Dubois-Briand via lists.openembedded.org wrote:
> Fixing devshell when some environment variables contain a back quote. On
> my side I had this issue using kitty terminal emulator, which sets the
> KITTY_PUBLIC_KEY environment variable [1]:
> KITTY_PUBLIC_KEY=1:`TB}~6^vgiFD2v6d}JRgt!X|qx#0~mO?&N=A1jfi
> 
> Trying to use devshell failed silently, but the parse error is visible
> while launching the do_terminal script by hand:
> 
> tmp/work/qemux86_64-poky-linux/linux-yocto/6.16.11+git/temp/run.do_terminal.2972397: line 120: unexpected EOF while looking for matching ``'
> WARNING: tmp/work/qemux86_64-poky-linux/linux-yocto/6.16.11+git/temp/run.do_terminal.2972397:119 exit 2 from 'export KITTY_PID="1985830"'
> WARNING: Backtrace (BB generated script): 
> 	#1: main, tmp/work/qemux86_64-poky-linux/linux-yocto/6.16.11+git/temp/run.do_terminal.2972397, line 119
> 
> Escaping back quotes allows to launch the devshell correctly.
> 
> Also adding a non-regression test. The whole bb.data.emit_var() function
> was not tested, I'm not sure if it was by choice or not, but I added
> some.
> 
> I tested the most basic code paths of bb.data.emit_var() but I'm not
> fully exhaustive. Notably, the return value remains untested as I was
> not able to figure out what it means and it appears to be unused.

Tests are good thanks. They're not present as the test suite didn't
exist when that code was written!

Cheers,

Richard