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

the option doubleQuotedMinMultiLineLength for yaml.stringify is not working as intended #512

Closed
aayshasura opened this issue Dec 19, 2023 · 3 comments
Labels
docs Documentation should be improved

Comments

@aayshasura
Copy link

Describe the bug
I am encountering an issue with the doubleQuotedMinMultiLineLength option in the yaml.stringify function that doesn't seem to behave as expected. The option in yaml.stringify doubleQuotedMinMultiLineLength is supposed to set min length of the double quoted string that should not be seperated to multiline with \. This is'nt an issue for single quoted strings or strings with no quotes in YAML Map representation.

To Reproduce
try to parse a yaml doc where a double quoted string is present as a YAMLMap and stringify it with options = {doubleQuotedMinMultiLineLength: x}, regardless of what x is the split is always happening from 76th character even though in the docs it is by default 40.

Expected behaviour
A clear and concise description of what you expected to happen.

I expect the doubleQuotedStrings present in the YAMLMap to be split to multiline with escape character \ only after the length passed in as options. if the options = {doubleQuotedMinMultiLineLength: 2} it should split to multiline after 2 characters and if its 400 it should split into multiline with escape character after 400 characters.

Versions (please complete the following information):

  • Environment: [e.g. Node.js 14.7.0 or Chrome 87.0]
  • yaml: [e.g. 1.10.0 or 2.0.0-2]

Additional context
Add any other context about the problem here.

@aayshasura aayshasura added the bug Something isn't working label Dec 19, 2023
@eemeli
Copy link
Owner

eemeli commented Dec 20, 2023

Could you provide JS code reproducing the results you think are wrong?

@aayshasura
Copy link
Author

I am using this inside a language extension server below is code that reads a yaml like language

async function updateStandardDataConnector(
  hasuraSettings: HasuraSettings,
  hasuraMetadata: Metadata,
  connection: Connection,
  dataConnector: CachedDataConnector,
  dataConnectorNode: YAMLMap,
  subgraph: string,
  session: HasuraSession
) {

  console.debug("==================================")
  console.debug(stringify(dataConnectorNode,{doubleQuotedMinMultiLineLength: 2}))
  console.debug(stringify(dataConnectorNode))
  console.debug(stringify(dataConnectorNode,{doubleQuotedMinMultiLineLength: 200}))
  console.debug("==================================") 

if the file it reads from looks like this
image

this is console log

==================================
kind: DataConnector
version: v1
definition:
  name: ts_connector
  url:
    singleUrl: "http://localhost:3000/thisurlisveryveryveryveryveryveryveryveryvery\
      veryveryveryverylong"

kind: DataConnector
version: v1
definition:
  name: ts_connector
  url:
    singleUrl: "http://localhost:3000/thisurlisveryveryveryveryveryveryveryveryvery\
      veryveryveryverylong"

kind: DataConnector
version: v1
definition:
  name: ts_connector
  url:
    singleUrl: "http://localhost:3000/thisurlisveryveryveryveryveryveryveryveryvery\
      veryveryveryverylong"

==================================

Here you can see that the option is not working no matter what option is passed.
The multiline split with escape "" behaviour doesn't happen if the singleUrl here was single -quoted or with no quotes and users are reporting this as a bug.

@eemeli
Copy link
Owner

eemeli commented Dec 20, 2023

Ah, the docs on the option should be adjusted a bit to clarify that the option is for (italics is currently missing):

Minimum length for double-quoted strings to use multiple lines to represent the value instead of escaping newlines.

To get the results you want, you'll want to also set lineWidth: 0.

@eemeli eemeli added docs Documentation should be improved and removed bug Something isn't working labels Dec 20, 2023
@eemeli eemeli closed this as completed in 1838a66 Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation should be improved
Projects
None yet
Development

No branches or pull requests

2 participants