eo-yaml
eo-yaml copied to clipboard
Folded Block Scalar is not working
Hello! I was trying to play with the example in readme and discovered that it's broken.
Simple example:
public static void main(String[] args) {
try {
final YamlInput input = Yaml.createYamlInput(new File("/Users/grascm/test.yaml"));
final YamlMapping map = input.readYamlMapping();
final String folded = map.foldedBlockScalar("folded");
final String folderString = map.string("folded");
final Collection<String> literalLines = map.literalBlockScalar("literal");
final String literalString = map.string("literal");
System.out.println("folded:");
System.out.println(folded);
System.out.println("folderString:");
System.out.println(folderString);
System.out.println("literalLines:");
System.out.println(literalLines);
System.out.println("literalString:");
System.out.println(literalString);
} catch (IOException e) {
e.printStackTrace();
}
}
Gives me folllowing output:
folded:
a long line split into
several short
lines for readability
folderString:
a long line split into
several short
lines for readability
literalLines:
[line 1, line 2, line 3]
literalString:
line 1
line 2
line 3
For the file with following content:
simple: plain_scalar
folded: >
a long line split into
several short
lines for readability
literal: |
line 1
line 2
line 3
I have tried to figure out what the problem is, and found, that any line with indent counts as newline here
I'm not familiar with yaml spec, so can't say anything about this behaviour, but it seems to broke provided example.
@GRascm what is the output of simply: System.out.println(map);
?
@GRascm what is the output of simply:
System.out.println(map);
?
it gives full file content:
simple: plain_scalar
folded: >
a long line split into
several short
lines for readability
literal: |
line 1
line 2
line 3
@GRascm Looking at your code and output with more attention, I don't really understand where exactly the problem is :D What's the problem, actually?
I expected output for folded
and foldedString
to be equal to a long line split into several short lines for readability
without newlines, according to your wiki
@GRascm right. I remember there was a small bug about this topic, it's about indentation. Folded scalars are tricky in YAML because not all NewLines should be ommited.
For instance this:
folded: >
a long line split into
several short
lines for readability
Should be read on a single line. But this:
folded: >
a long line split into
several short lines
but this is on a new line because it has a deeper indentation
will get you this:
a long line split into several short lines
but this is on a new line because it has a deeper indentation
Do you need this bugfix now, is it causing you problems? Or were you just digging for bugs? :D
@amihaiemil
Do you need this bugfix now, is it causing you problems? Or were you just digging for bugs? :D
I was looking for a yaml library for my new pet project, so there is no urgency about this bug (cause there is no project yet :D). I'm not even sure that i will need such functionality. So i guess it's more like "digging for bugs".
@GRascm you can use it for your project. It's quite stable even though there a few reported bugs. Interfaces are a big advantage, you can decorate the existing objects and add any functionality you may need :)
This issue should also be fixed in 7.0.4. If you still encounter it, feel free to open another Issue.