`range` of a Block Scalar should match its `value`
Closed this issue · 3 comments
Describe the bug
The "start offset" of a Block Scalar value should be the beginning of the string value, not the "|-" part
v Range should not starts from here
test: |-
This is a string
To Reproduce
test: |-
This is a string
var yaml = require("yaml")
var text = "test: |-\n This is a string"
var doc = yaml.parseDocument(text, { keepSourceTokens: true, strict: false })
console.log("value:", doc.contents.items[0].value.value) // "This is a string"
console.log("offset:", doc.contents.items[0].value.range[0]) // 6, should be 13 instead
Expected behaviour
test: |-
This is a string
^ The range offset should start here
Versions:
yaml
: 2.4.1
Why?
Well I'm actually trying to get the exact offset of the string value
. By instinct I would think doc.contents.items[0].value.range
only indicating the start and end of the value
itself, yet it seems covering something else as well.
I did not read through the YAML specification. If the value.range
does work as intended, that should be fine.
I will try to calculate it through srcToken
though it is a bit of complicated 😂
For a block scalar, the header is a required part of the source to determining its value. So what you're asking for would be analogous for the range of a quoted scalar like "foo"
to not include the "
marks.