Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String folding of certain folded block scalar values is ugly #422

Closed
havran opened this issue Nov 11, 2022 · 4 comments
Closed

String folding of certain folded block scalar values is ugly #422

havran opened this issue Nov 11, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@havran
Copy link

havran commented Nov 11, 2022

Describe the bug
Hi. Seems like for some specific multiline strings, output of stringify() is formatted invalid.

To Reproduce

Example:

console.log(
  stringify({
    'nginx.ingress.kubernetes.io/configuration-snippet':
      'location ~* ^/sites/aaaaaaa.aa/files/(.+) {\n  return 302 https://process.aaaaaaa.aa/sites/aaaaaaa.aa/files/$1;\n}\nlocation ~* ^/partner-application/cls/(.+) {\n  return 301 https://process.aaaaaaa.aa/partner-application/cls/$1$is_args$args;\n}\n',
  })
);

Output:

nginx.ingress.kubernetes.io/configuration-snippet: >
  location ~*
  ^/sites/aaaaaaa.aa/files/(.+) {
    return 302 https://process.aaaaaaa.aa/sites/aaaaaaa.aa/files/$1;
  }

  location ~* ^/partner-application/cls/(.+) {
    return 301 https://process.aaaaaaa.aa/partner-application/cls/$1$is_args$args;
  }

Expected behaviour

Expected output:

nginx.ingress.kubernetes.io/configuration-snippet: >
  location ~* ^/sites/aaaaaaa.aa/files/(.+) {
    return 302 https://process.aaaaaaa.aa/sites/aaaaaaa.aa/files/$1;
  }
  location ~* ^/partner-application/cls/(.+) {
    return 301 https://process.aaaaaaa.aa/partner-application/cls/$1$is_args$args;
  }

Versions (please complete the following information):

Node:

$ node --version
v16.18.1

Yaml: 2.1.3

Note: edited and site name was redacted. I try use example.com but in this case there was expected output. Probably problem is related with long lines?

@havran havran added the bug Something isn't working label Nov 11, 2022
@eemeli
Copy link
Owner

eemeli commented Nov 11, 2022

It does look like the string folding is a bit buggy there. The value represented by the stringified result is valid and does match the source, but there's no good reason why that first line should be folded like that.

@havran
Copy link
Author

havran commented Nov 11, 2022

Sorry, I do not notice, there are option related with lineWidth, and this fix my problem. Closing :-)

console.log(
  stringify(
    {
      'nginx.ingress.kubernetes.io/configuration-snippet':
        'location ~* ^/sites/aaaaaaa.aa/files/(.+) {\n  return 302 https://process.aaaaaaa.aa/sites/aaaaaaa.aa/files/$1;\n}\nlocation ~* ^/partner-application/cls/(.+) {\n  return 301 https://process.aaaaaaa.aa/partner-application/cls/$1$is_args$args;\n}\n',
    },
    { blockQuote: 'literal', lineWidth: 0 }
  )
);

Output is OK now:

nginx.ingress.kubernetes.io/configuration-snippet: |
  location ~* ^/sites/aaaaaaa.aa/files/(.+) {
    return 302 https://process.aaaaaaa.aa/sites/aaaaaaa.aa/files/$1;
  }
  location ~* ^/partner-application/cls/(.+) {
    return 301 https://process.aaaaaaa.aa/partner-application/cls/$1$is_args$args;
  }

Thank you!

@havran havran closed this as completed Nov 11, 2022
@eemeli
Copy link
Owner

eemeli commented Nov 11, 2022

No, this is still a bug that should be fixed. The > style folding of your input is bad, even if it is valid.

@eemeli eemeli reopened this Nov 11, 2022
@eemeli eemeli changed the title Multiline strings is formated invalid with stringify() String folding of certain folded block scalar values is ugly Nov 11, 2022
@havran
Copy link
Author

havran commented Nov 11, 2022

True, I see it now. Happy to found new bug :-) blockQuote: literal + lineWidth: 0 solve this for me. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants