yamllint icon indicating copy to clipboard operation
yamllint copied to clipboard

Syntax error on valid characters in anchor names

Open Freso opened this issue 1 year ago • 1 comments

yamllint complains about the use of periods (.) in anchor names. As far as I can discern, ns-anchor-char allows all ns-chars except for c-flow-indicators (,[]{}).

Periods (.) are x2E which is well within the range of [x20-x7E] given in c-printable and is not one of the chars excluded from ns-char via b-char, c-byte-order-mark, or s-white.

I don’t see any way to configure yamllint to not balk on this, or at least reduce this to a warning (other than comment-disabling). I can definitely see limiting anchor names to alphanumeric characters to be desired for many use cases (for compatibility/interoperability), but the spec allows for a wider range of characters used here, so this should probably reasonably be a configuration toggle.

%YAML 1.2
---
test:
  - &test-with-.period "This is a test of an anchor with a period (`.`)."
test2:
  - *test-with-.period
...
> yamllint --version
yamllint 1.35.1
> yamllint test.yaml
test.yaml
  4:16      error    syntax error: expected alphabetic or numeric character, but found '.' (syntax)

Freso avatar Aug 25 '24 13:08 Freso

I just want to comment that the underlying issue is in pyyaml. It is more restrictive than the YAML spec regarding what is allowed in anchor names. https://github.com/yaml/pyyaml/issues/373 https://github.com/yaml/pyyaml/pull/389 The current pyyaml maintainer wants to keep it that way. The same is true for libyaml, btw.

Not sure if yamllint can work around that syntax error from pyyaml.

perlpunk avatar Aug 25 '24 21:08 perlpunk