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

Node range overlaps #262

Closed
evidolob opened this issue Apr 23, 2021 · 2 comments
Closed

Node range overlaps #262

evidolob opened this issue Apr 23, 2021 · 2 comments
Labels
docs Documentation should be improved

Comments

@evidolob
Copy link

Describe the bug
Node range overlaps in some cases.
For example one node has range [0, 22, 22] and next node has [22, 42, 42] offsets, which is impossible one char cannot belongs to two different nodes.

To Reproduce
Run this test:

    test('Range', () => {
      const text =`scripts:
  node1: test
  node2: test
authors:
  - name:Foo
  - email: bar
`
      const composer = new Composer();
      const parser = new Parser();
      const tokens = parser.parse(text);
      const docs = composer.compose(tokens);
      const doc = Array.from(docs)[0];
      expect(((doc.contents as YAMLMap).get('scripts') as YAMLMap).range).toEqual([11, 37, 37]);
      expect((findPair((doc.contents as YAMLMap).items, 'authors')?.key as Node).range).toEqual([38, 44, 44]);
    })

thous test fail as key authors has range [37, 44, 44] but scripts map ends on 37th character. It seems that key authors starts with \n on previous line.

Expected behaviour
Nodes range should not overlap.

Versions (please complete the following information):

  • Environment: Node.js 12
  • yaml: 2.0.0-5
@evidolob evidolob added the bug Something isn't working label Apr 23, 2021
@eemeli
Copy link
Owner

eemeli commented Apr 23, 2021

This is working as intended. The end of a range is the position one past what's included in the node:

const text =`scripts:
  node1: test
  node2: test
authors:
  - name:Foo
  - email: bar
`

text.substring(11, 37) === 'node1: test\n  node2: test\n'
text.substring(37, 44) === 'authors'

@evidolob
Copy link
Author

Hm, OK, can you update jsdoc for ranges, and explain what that numbers mean?
I mean that value-end,node-end should be treated as indexEnd param for substring method.

@eemeli eemeli added docs Documentation should be improved and removed bug Something isn't working labels Apr 23, 2021
@eemeli eemeli closed this as completed in 5216dad May 14, 2021
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