Forced single-quoted or literal style emits raw NUL and U+0001

Aperta
#1,506 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

  • #1508 di @himanshu748 — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
data

Direzione di ricerca

The bug is in src/emitterutils.cpp: IsValidSingleQuotedScalar and IsValidLiteralScalar lack a non-printable check (both carry a TODO), so the double-quoted fallback never runs. Read how the emitter picks a style, then reproduce with the snippet in the issue and inspect the bytes with xxd. Done when NUL and U+0001 under SingleQuoted or Literal produce escaped output, and the Auto and DoubleQuoted results are unchanged. Closed PR #1508 was not merged, so check why before starting.

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

Descrizione

On master 1e0876c, forcing YAML::SingleQuoted or YAML::Literal on a string containing NUL (U+0000) or U+0001 writes the raw character into the output. Auto and DoubleQuoted escape them correctly.

YAML 1.2.2 section 5.1: "On output, a YAML processor must only produce only characters in this printable subset. Characters outside this set must be presented using escape sequences." NUL and U+0001 are outside that set, and the JSON-compatibility allowance for quoted scalars only covers non-C0 characters. TAB, LF, CR and NEL are allowed and not reported here. PyYAML and a ruamel.yaml loader set to YAML 1.2 both reject the raw output.

The repro uses UTF-8 strings and the default UTF-8 output; the reported NUL/U+0001 are scalar content characters, not zero bytes in UTF-16/UTF-32 encoding.

Repro: emit "a" + c + "b" for c in {0x00, 0x01} with Auto, SingleQuoted, Literal and DoubleQuoted, then inspect with xxd.

#include <yaml-cpp/yaml.h>
#include <fstream>
#include <string>

int main() {
    const char values[] = {char(0x00), char(0x01)};
    const YAML::EMITTER_MANIP styles[] = {
        YAML::Auto, YAML::SingleQuoted, YAML::Literal, YAML::DoubleQuoted
    };
    const char* names[] = {"auto", "single", "literal", "double"};
    for (unsigned i = 0; i < 2; ++i) {
        for (unsigned j = 0; j < 4; ++j) {
            const std::string s = std::string("a") + values[i] + "b";
            const std::string path = std::to_string(i) + "-" + names[j] + ".yaml";
            std::ofstream f(path, std::ios::binary);
            YAML::Emitter e(f);
            e << styles[j] << s;
        }
    }
}

Cause: IsValidSingleQuotedScalar and IsValidLiteralScalar in src/emitterutils.cpp have no non-printable check (both carry a TODO), so the double-quoted fallback never triggers.

Minor note: U+007F (DEL) is written raw in every style. It's outside c-printable, though the grammar's JSON-compatibility rule admits it inside quoted scalars, and section 5.1 recommends escaping non-printables even there. I'm not claiming quoted DEL is invalid syntax; the raw literal-style case is outside the literal character set. Parsers above also reject it.

I used AI tools to find and reproduce this; I reviewed it myself.

Lingua principale
C++
Stelle
6.1k
Fork
2.2k
Merge medio
22h 2m
PR unite (30g)
1

Preparare l'ambiente

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 jbeder/yaml-cpp

Tutte le issue di jbeder/yaml-cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.