jeremyfa / yaml.js

Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.
MIT License
889 stars 142 forks source link

Parses incorrectly multiple lines properties #109

Open gartz opened 6 years ago

gartz commented 6 years ago

When using the > to parse multiple lines, the result is invalid, example:

File example:

      NODE_CONFIG: >
        CACHE:
          READWRITE:
            # Whether or not Memcache is disabled. If it is disabled, all of the commands will simply return null as if
            # the key does not exist
            disabled: false

            # The list of hosts to connect to. Can be a string for a single host or an array for multiple hosts. If none
            # provided, defaults to localhost
            hosts:
              - memcached:11211
        LOG:
          WINSTON:
            TRANSPORTS:
              - TYPE: Console
                OPTIONS:
                  level: silly
                  name: console-log
                  handleExceptions: true
                  colorize: false
                  prettyPrint: true
                  timestamp: true

Result:

      NODE_CONFIG: "CACHE:  READWRITE:\n    disabled: false\n\n    hosts:\n      - memcached:11211\nLOG:  WINSTON:\n    TRANSPORTS:\n      - TYPE: Console\n        OPTIONS:\n          level: silly\n          name: console-log\n          handleExceptions: true\n          colorize: false\n          prettyPrint: true\n          timestamp: true\n"

The correct result should be:

      NODE_CONFIG: "CACHE:\n  READWRITE:\n    disabled: false\n\n    hosts:\n      - memcached:11211\nLOG:\n  WINSTON:\n    TRANSPORTS:\n      - TYPE: Console\n        OPTIONS:\n          level: silly\n          name: console-log\n          handleExceptions: true\n          colorize: false\n          prettyPrint: true\n          timestamp: true\n"

It's ignoring the first level breakline and only doing in the next nested levels.