Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Fix "str|format" string formatting to match spec (%s formatting, not {} formatting), also support "str.format" syntax

Aperta
#267 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
tooling

Direzione di ricerca

Inizia individuando l’implementazione esistente del filtro str|format e il punto di ingresso del parser o dell’evaluator per le chiamate ai metodi delle stringhe. Confronta entrambe le forme con gli esempi di template e il comportamento di Python Jinja2 nell’issue. Il lavoro è completato quando la formattazione con % funziona per str|format, str.format supporta la formattazione con {} e gli output mostrati corrispondono.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The jinja2 spec alludes to two flavors of format -- str.format and str|format -- that seemingly have / support different string formatting syntaxes.
https://jinja.palletsprojects.com/en/2.10.x/templates/

The str.format syntax appears to support standard {} string formatting (like fmt::format), whereas str|format appears to support % string formatting (like printf). Here's a quick mapping / handy guide as I understand it.

  • jinja2 "hello %"|format("world") -> Python `"hello %" % "world"
  • jinja2 "hello {}".format("world") -> Python "hello {}".format("world")

Here's a template with corresponding Python jinja2 output.

# template; note that the "2 {}" case fails to compile if arg is passed
{{ "1 %s"|format(0) }}
{{ "2 {}"|format() }}
{{ "3 %s".format(0) }}
{{ "4 {}".format(0) }}

# Python jinja2 output
1 0
2 {}
3 %s
4 0

And a similar template with its corresponding jinja2cpp output.

# template; note that 3/4 are missing because `.format` syntax not currently supported in jinja2cpp
{{ "3 %s"|format(0) }}
{{ "4 {}"|format(0) }}

# jinja2cpp output
3 %s
4 0

From these examples, we can see a couple key differences between jinja2cpp and Python jinja2.

  1. str|format syntax in jinja2cpp behaves like str.format syntax in Python jinja2. That is to say that jinja2cpp uses {} string formatting for str|format when it should instead use %s string formatting (per spec / Python parity).
  2. str.format syntax is not supported in jinja2cpp. This should have the {} string formatting behavior, so existing str|format implementation in jinja2cpp could perhaps largely be reused / repurposed to support this.
Lingua principale
C++
Stelle
602
Fork
114
Merge medio
2h 49m
PR unite (30g)
378

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jinja2cpp/Jinja2Cpp

Tutte le issue di jinja2cpp/Jinja2Cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.