eo-yaml icon indicating copy to clipboard operation
eo-yaml copied to clipboard

Folded Block Scalar is not working

Open grascm opened this issue 4 years ago • 7 comments

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 avatar Jul 08 '20 14:07 grascm

@GRascm what is the output of simply: System.out.println(map);?

amihaiemil avatar Jul 08 '20 14:07 amihaiemil

@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 avatar Jul 08 '20 14:07 grascm

@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?

amihaiemil avatar Jul 08 '20 14:07 amihaiemil

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 avatar Jul 08 '20 14:07 grascm

@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 avatar Jul 08 '20 14:07 amihaiemil

@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 avatar Jul 08 '20 15:07 grascm

@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 :)

amihaiemil avatar Jul 08 '20 16:07 amihaiemil

This issue should also be fixed in 7.0.4. If you still encounter it, feel free to open another Issue.

amihaiemil avatar Feb 06 '23 20:02 amihaiemil