Skip to content

stat: fix %N quoting of filenames containing control characters#12330

Open
fullwoodenshovel wants to merge 1 commit into
uutils:mainfrom
fullwoodenshovel:fix-stat-percent-n-control-chars
Open

stat: fix %N quoting of filenames containing control characters#12330
fullwoodenshovel wants to merge 1 commit into
uutils:mainfrom
fullwoodenshovel:fix-stat-percent-n-control-chars

Conversation

@fullwoodenshovel
Copy link
Copy Markdown

@fullwoodenshovel fullwoodenshovel commented May 16, 2026

%N was outputting raw control characters (e.g. newlines) in filenames instead of escaping them. Fixed by replacing the local quote_file_name implementation with uucore::quoting_style::escape_name, which correctly implements shell-escape-always behaviour. Added tests for filenames containing single and contiguous newlines.
Fixes #9925. More info and examples there.

There is a previous attempt at this fix in #9926, but it only handles \n specifically, and doesn't match GNU exactly as it adds a $'...' block around the whole string instead of only around the control characters. This PR instead uses uucore::quoting_style::escape_name which correctly handles all control characters consistently with the rest of the codebase and GNU.

@fullwoodenshovel fullwoodenshovel force-pushed the fix-stat-percent-n-control-chars branch from dc54600 to 9b32ed5 Compare May 16, 2026 17:33
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.

stat: %N fails with new line

1 participant