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

False positive for scientific notation #495

Closed
0xallie opened this issue Oct 1, 2022 · 1 comment · Fixed by #496
Closed

False positive for scientific notation #495

0xallie opened this issue Oct 1, 2022 · 1 comment · Fixed by #496

Comments

@0xallie
Copy link

0xallie commented Oct 1, 2022

Given the following YAML file:

foo: 1e2a

Running yamllint -d 'rules: {float-values: {forbid-scientific-notation: true}}' test.yaml produces this error:

test.yaml
  1:6       error    forbidden scientific notation "1e2a"  (float-values)

This is incorrect, as it's actually parsed as a string:

❯ python -c 'import yaml; print(yaml.safe_load(open("test.yaml")))'
{'foo': '1e2a'}
❯ python -c 'from ruamel.yaml import YAML; print(YAML().load(open("test.yaml")))'
ordereddict([('foo', '1e2a')])

❯ yamllint --version
yamllint 1.28.0     
@adrienverge
Copy link
Owner

Hello @nyuszika7h, thanks for the report!

I can confirm the bug, and it actually occurs on all options of the float-values rule:

- .1two3
- 1e2a
- .NaNa
- .Infinit∞
yamllint -d 'rules: {float-values: {require-numeral-before-decimal: true,
                                    forbid-scientific-notation: true,
                                    forbid-nan: true,
                                    forbid-inf: true}}' /tmp/file.yaml

/tmp/file.yaml
  1:3       error    forbidden decimal missing 0 prefix ".1two3"  (float-values)
  2:3       error    forbidden scientific notation "1e2a"  (float-values)
  3:3       error    forbidden not a number value ".NaNa"  (float-values)
  4:3       error    forbidden infinite value ".Infinit∞"  (float-values)

I guess the writing of tests wasn't thorough enough on #465.

I'll work on a fix.

adrienverge added a commit that referenced this issue Oct 2, 2022
The rule correctly reports number values like `.1`, `1e2`, `.NaN` and
`.Inf`, but it also reported false positives on strings like `.1two3`,
`1e2a`, `.NaNa` and `.Infinit∞`.

The regexps need to end with an end delimiter (`$`) otherwise longer
strings can be matched too.

Fixes #495
adrienverge added a commit that referenced this issue Oct 4, 2022
The rule correctly reports number values like `.1`, `1e2`, `.NaN` and
`.Inf`, but it also reported false positives on strings like `.1two3`,
`1e2a`, `.NaNa` and `.Infinit∞`.

The regexps need to end with an end delimiter (`$`) otherwise longer
strings can be matched too.

Fixes #495
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant