@std/yaml: stringify() with condenseFlow wraps already quoted keys in a second pair of quotes

オープン 初心者向け
#7,362 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@sebxt がすでに取り組んでいます。

2026年10月19日 から。

  • #7363 @sebxt による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
deno, typescript
領域
backend

調査の方向性

yaml/_dumper_state.ts の DumperState.stringifyFlowMapping() から始めます。ここでは、シリアライズされたキーが再び囲まれています。指定された condenseFlow: true の例で再現し、次にフローマッピングの YAML stringify テストと往復パースを確認します。引用符付きやエスケープされたキー(長いキーを含む)が有効な YAML として stringify され、元のオブジェクトにパースし直せれば完了です。

索引モデルが issue の本文から書いたものです。

説明

What happens

With condenseFlow: true, stringify() wraps every flow mapping key in double quotes, even when the key was already emitted as a quoted scalar. Keys that need quoting (numeric strings, true, #, the empty string, strings with " or a newline) come out double wrapped. Parsing the output either returns a different key or throws.

import { parse, stringify } from "jsr:@std/yaml";

const options = { flowLevel: 0, condenseFlow: true };

stringify({ "1": 1 }, options);    // {"'1'":1}    parses back as { "'1'": 1 }
stringify({ "": 1 }, options);     // {"''":1}     parses back as { "''": 1 }
stringify({ 'a"b': 1 }, options);  // {"a"b":1}    parse() throws
stringify({ "a\nb": 1 }, options); // {""a\nb"":1} parse() throws
stringify({ "a\\nb": 1 }, options); // {"a\nb":1}  parses back with a real newline

Keys longer than 1024 characters also get the ? explicit key marker inside the quotes, so the parsed key starts with ? .

What should happen

The output should be valid YAML that parses back to the same object, for example {'1':1} and {"a\"b":1}.

Root cause

DumperState.stringifyFlowMapping() in yaml/_dumper_state.ts builds each pair as quote + keyPrefix + keyString + quote, where keyString is the already serialized key and may already be quoted. Plain keys are also wrapped without escaping, so a plain key containing \ or " changes meaning inside the double quotes.

主要言語
TypeScript
スター
3.6k
フォーク
713
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

denoland/std のほかの issue

denoland/std の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。