Skip to content

fix: expand format placeholder followed by a literal '}'#2060

Open
upuddu wants to merge 1 commit into
sharkdp:masterfrom
upuddu:fix/format-placeholder-before-brace
Open

fix: expand format placeholder followed by a literal '}'#2060
upuddu wants to merge 1 commit into
sharkdp:masterfrom
upuddu:fix/format-placeholder-before-brace

Conversation

@upuddu

@upuddu upuddu commented Jul 7, 2026

Copy link
Copy Markdown

A format placeholder immediately followed by a literal } wasn't expanded: fd --format '{}}' emitted a literal {} and dropped the trailing brace instead of producing <path>}. The parser fell through to a literal branch whenever a placeholder was followed by }; removing it lets the } be treated as ordinary literal text like everywhere else. Since --exec shares the parser, fd -x echo '{.}}' was affected too.

A placeholder immediately followed by a literal '}' (e.g. '{}}' or '{.}}')
was treated as fixed text instead of being expanded. The parser detected the
placeholder pattern but, when the next character was '}', fell through to a
branch that copied the whole sequence verbatim and dropped the trailing '}'.

Remove that branch so the placeholder is always emitted and the following '}'
is handled as ordinary literal text. This affects both --format and --exec,
which share the template parser.
@tmccombs

tmccombs commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

What you describe is expected behavior. Currently, "}}" is the way to escape a "}" character, so the "}}" is replaced witha literal "}", and the "{" is unmatched, so not replaced.

I haven't looked at this deeply, but I am guessing this is effectively changing the eacape syntax, which would be a breaking change. Such a change should probably have more discussion in an issue before it is merged.

@upuddu

upuddu commented Jul 8, 2026

Copy link
Copy Markdown
Author

Thanks for taking a look, and fair point, I don't want to quietly change the escaping rules either.

Digging into the parser, I think the change is narrower than "changing the escape syntax." {{{ and }}} are handled exactly as before, and the documented way to emit a literal {} ({{}}) is unchanged. The only strings whose output changes are a placeholder immediately followed by a single }: {}}, {/}}, {.}}, etc.

The reason I filed it as a bug is consistency of the lone }. A single, un-doubled } is already treated as ordinary literal text everywhere else in a format string (e.g. --format 'a}b' emits a}b). The one exception was directly after a placeholder, where the trailing } silently swallowed the placeholder, so {}} produced the literal text {} instead of <path>}. Removing that special case is what makes a lone } behave the same in that position as everywhere else.

That said, you're right that it's technically a behavior change for {}} specifically, and I'm happy to follow your process on it. Want me to open an issue laying this out (bug-vs-breaking-change, the consistency argument, and the fact that the {{}} escape is unaffected) so it can be decided there before merging? Happy to hold the PR until then.

@tavianator

Copy link
Copy Markdown
Collaborator

I think the sane thing to do here is maximum munch tokenization, same as most lexers/parsers do. Although IMO {.}} should be a syntax error, you should be forced to write {.}}}

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