Skip to content

fix(completion): handle NUL-separated package candidates - #1553

Open
Scott-Nx wants to merge 1 commit into
Morganamilo:masterfrom
Scott-Nx:master
Open

fix(completion): handle NUL-separated package candidates#1553
Scott-Nx wants to merge 1 commit into
Morganamilo:masterfrom
Scott-Nx:master

Conversation

@Scott-Nx

Copy link
Copy Markdown

Fix Bash completion warning caused by NUL-separated package candidates from paru -Pc.

Problem

When completing package names with Bash completion, for example:

paru -S gpu-screen-reco<Tab>

Bash prints:

bash: warning: command substitution: ignored null byte in input

The warning comes from _paru_pkg():

_arch_compgen "$(paru -Pc)"

paru -Pc emits NUL bytes. Bash command substitution cannot preserve NUL bytes, so Bash drops them and prints the warning.

On my system:

$ paru -Pc | LC_ALL=C tr -cd '\000' | wc -c
1734

Fix

Convert NUL bytes to newlines before passing the output into _arch_compgen:

_arch_compgen "$(paru -Pc | tr '\000' '\n')"

This preserves candidate separation and avoids the Bash warning.

Testing

Confirmed that paru -Pc emits NUL bytes:

$ paru -Pc | LC_ALL=C tr -cd '\000' | wc -c
1734

Confirmed that converting NUL bytes to newlines removes them:

$ paru -Pc | tr '\000' '\n' | LC_ALL=C tr -cd '\000' | wc -c
0

After applying the patch, Bash completion works without the warning:

paru -S gpu-screen-reco<Tab>

Expected candidates are shown:

$ paru -S gpu-screen-recorder
gpu-screen-recorder               gpu-screen-recorder-notification  gpu-screen-recorder-ui

`paru -Pc` may emit NUL-separated completion candidates. Passing that
output directly through Bash command substitution makes Bash drop the
NUL
bytes and print:

  bash: warning: command substitution: ignored null byte in input

Convert NUL bytes to newlines before passing the output to
`_arch_compgen`
so package completion keeps candidate separation without triggering the
warning.
@pfeifferj

Copy link
Copy Markdown
Collaborator

I can't reproduce the issue you're trying to fix with this PR

@Scott-Nx

Scott-Nx commented May 19, 2026

Copy link
Copy Markdown
Author

I think this may depend on whether paru -Pc emits NUL-separated candidates on the local system.

On my machine, _paru_pkg() currently does this:

_arch_compgen "$(paru -Pc)"

and paru -Pc contains NUL bytes:

$ paru -Pc | LC_ALL=C tr -cd '\000' | wc -c
1734

Bash command substitution cannot preserve NUL bytes, so Bash drops them and prints:

bash: warning: command substitution: ignored null byte in input

Could you check whether paru -Pc contains NUL bytes on your system?

paru -Pc | LC_ALL=C tr -cd '\000' | wc -c

If this returns 0, that would explain why you cannot reproduce the warning locally. If it returns a non-zero value, the warning should be reproducible when the completion path calls _paru_pkg().

This patch is mostly a defensive normalization rather than a behavior change. For systems where paru -Pc already produces shell-safe output, completion behavior should stay effectively the same. For systems where paru -Pc emits NUL-separated output, converting NUL bytes to newlines before Bash command substitution avoids the warning while keeping candidate separation usable for completion.

The patch changes the input passed to _arch_compgen from:

_arch_compgen "$(paru -Pc)"

to:

_arch_compgen "$(paru -Pc | tr '\000' '\n')"

TL;DR

This is not intended to change completion behavior for systems that already work. It only normalizes NUL-separated output before Bash command substitution, because Bash cannot preserve NUL bytes anyway.

@pfeifferj

Copy link
Copy Markdown
Collaborator

my guess is that your ~/.cache/paru/packages.aur is corrupted with raw gzip bytes

@sparshjain265

Copy link
Copy Markdown

I am getting the same warning as @Scott-Nx. paru -Pc | LC_ALL=C tr -cd '\000' | wc -c reveals I have 1713 NUL bytes, and this fix gets rid of these warnings for me without any noticeable incorrectness in the behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants