Puzzled by \n\n behaviour in a yaml file
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 25/100
Direção de pesquisa
Comece reproduzindo os exemplos de YAML.load, YAML.safe_load e YAML.dump em um script Ruby mínimo, com foco em strings entre aspas e nas formas escalares > e |. Determine se o comportamento de novas linhas e formatação é um comportamento pretendido de YAML/Psych ou um defeito; considera-se concluído quando houver uma explicação documentada ou um escopo do problema confirmado e testável.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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 😄
- Linguagem predominante
- Ruby
- Estrelas
- 596
- Forks
- 228
- Merge médio
- 24min
- PRs com merge (30d)
- 5
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de ruby/psych
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia
-
Sexagesimal scalars are mis-scannedTalvez já em andamento @ihamzatarar assumiu há 13 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
ruby/psych#814 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Documentation
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsTalvez já em andamento @Halvanhelv assumiu há 83 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 55/100
Mantenedores costumam responder em até 1 dia
-
Psych::Emitter#start_document: tag-directive handles and prefixes are aliased as raw `char *`, and the Strings die inside the loopTalvez já em andamento @ninjapanzer assumiu há 14 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 68/100
ruby/psych#812 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
🐛 bug 👩💻 équipe CE
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
betagouv/conseillers-entreprises#4835 ·
Mantenedores costumam responder em até 1 dia
-
Action: a `test` glob with a gem older than 1.9.0 fails with `no such file` and no version hintAbertabacklog enhancement github_actions priority: low risk: low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
davidteren/mutineer#646 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
metanorma/isodoc#965 · 1 comentário ·
Mantenedores costumam responder em até 1 dia