Puzzled by \n\n behaviour in a yaml file
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず、最小限の Ruby スクリプトで YAML.load、YAML.safe_load、YAML.dump の例を再現し、引用符付き文字列と > および | のスカラー形式に焦点を当てます。改行とフォーマットの挙動が意図された YAML/Psych の挙動なのか、それとも不具合なのかを判断します。完了の条件は、文書化された説明、または確認済みでテスト可能な問題のスコープです。
索引モデルが issue の本文から書いたものです。
説明
I could not find documentation on this behaviour so I thought it would be better to share about it and be told I'm wrong than to keep to myself.
In a piece I'm writing, I load, modify then dump a piece of data.
load then dump being called one after the other in a loop would always produce the same values. As a human reading the yaml representation, I can see an extra \n being present in the yaml that is not there in the ruby representation:
require 'yaml'
yaml = <<YAML
en:
test: >
multiline a
multiline b
multiline c
YAML
data = YAML.load(yaml)
=> {"en"=>{"test"=>"multiline a multiline b multiline c\n"}}
new_yaml = YAML.dump(data)
=> "---\nen:\n test: 'multiline a multiline b multiline c\n\n'\n"
new_data = YAML.safe_load(new_yaml)
=> {"en"=>{"test"=>"multiline a multiline b multiline c\n"}}
There seems to be a behaviour where only 2 subsequent line returns would be considered as a actual line return:
YAML.load("---\nen:\n test: 'this\nis\na\n\ntest'")
=> {"en"=>{"test"=>"this is a\ntest"}}
While I understand that \n in the yaml file structure might have a special meaning, I am surprised to also see it behave the same way when within a quoted piece of information.
I'm also wondering why when passing in a file using the > format, that the output is returned as a quoted string instead of re-using the same format. I understand that the code cannot keep track of the "format used" when first loading the data as we only have a Hash, but in case of | this is the format being used for a dump and it seems much more natural for a human to interact with it (main reason why I end up using yaml)
require 'yaml'
yaml = <<YAML
en:
test: |
multiline a
multiline b
multiline c
YAML
YAML.dump(YAML.load(yaml))
=> "---\nen:\n test: |\n multiline a\n multiline b\n multiline c\n"
So all of this makes me wonder if it is just about documentation as the intended behaviours or if these are symptoms of some kind of issue.
Any insight is greatly appreciated, thank you 😄
- 主要言語
- Ruby
- スター
- 596
- フォーク
- 228
- 平均マージ
- 24分
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/psych のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
Sexagesimal scalars are mis-scanned対応中かも @ihamzatarar が 13 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Documentation
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 strings対応中かも @Halvanhelv が 83 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
-
Psych::Emitter#start_document: tag-directive handles and prefixes are aliased as raw `char *`, and the Strings die inside the loop対応中かも @ninjapanzer が 14 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
🐛 bug 👩💻 équipe CE
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
betagouv/conseillers-entreprises#4835 ·
メンテナーはふだん 1 日以内に返信
-
Action: a `test` glob with a gem older than 1.9.0 fails with `no such file` and no version hintオープンbacklog enhancement github_actions priority: low risk: low
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
davidteren/mutineer#646 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
metanorma/isodoc#965 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信