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

Octal Numbers are handled incorrectly in equality and comparison checks #1977

Open
dikderoy opened this issue Mar 12, 2024 · 0 comments
Open
Labels

Comments

@dikderoy
Copy link

Describe the bug

equality and math gt and lt checks (==, >, <) evaluate to false
when they should evaluate to true

Version of yq: 4.42.1
Operating system: mac
Installed via: homebrew

Input Yaml

data1.yml:

old_octal: 0644 # YAML 1.1
new_octal: 0o644 # YAML 1.2

Command

cat data1.yml | yq '
to_entries | [ .[] | with( . 
 ; ._type = (.value | type)
 | .eq0644 = (.value == 0644)
 | .eq420 = (.value == 420)
 | .gt419 = (.value > 419)
 | .lt421 = (.value < 421)
 | .gt0643 = (.value > 0643)
 | .lt0645 = (.value < 0645)
) ]'

Actual behavior

- key: old_octal
  value: 0644
  _type: '!!int'
  eq0644: true
  eq420: false
  gt419: true
  lt421: false
  gt0643: true
  lt0645: true
- key: new_octal
  value: 0o644
  _type: '!!int'
  eq0644: false
  eq420: false
  gt419: true
  lt421: true
  gt0643: false
  lt0645: true

Expected behavior

- key: old_octal
  value: 0644
  _type: '!!int'
  eq0644: true
  eq420: true
  gt419: true
  lt421: true
  gt0643: true
  lt0645: true
- key: new_octal
  value: 0o644
  _type: '!!int'
  eq0644: true
  eq420: true
  gt419: true
  lt421: true
  gt0643: true
  lt0645: true

Additional information

probably connected - difference between YAML 1.1 and YAML 1.2 for octals when exporting to JSON:

command:

> cat data1.yml | yq -o json

output:

{
  "old_octal": 644,
  "new_octal": 420
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant