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

fix(yaml): fix Boolean object handling #5876

Conversation

timreichen
Copy link
Contributor

@timreichen timreichen commented Aug 30, 2024

Closes #5857

@timreichen timreichen requested a review from kt3k as a code owner August 30, 2024 20:44
@github-actions github-actions bot added the yaml label Aug 30, 2024
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.35%. Comparing base (f86e911) to head (902aaad).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5876   +/-   ##
=======================================
  Coverage   96.34%   96.35%           
=======================================
  Files         479      479           
  Lines       38674    38673    -1     
  Branches     5631     5630    -1     
=======================================
+ Hits        37260    37262    +2     
+ Misses       1370     1367    -3     
  Partials       44       44           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kt3k, PTAL at the related issue. Do you agree this is a fix? I think it is as it fixes expected behavior.

@kt3k kt3k changed the title fix(yaml): remove boolean instance validation fix(yaml): fix Boolean object handling Sep 3, 2024
@kt3k
Copy link
Member

kt3k commented Sep 3, 2024

This changes the result of stringify({ foo: new Boolean(true) }) to foo: {} instead of foo: true. I don't think this matches the expectation of the users.

I think we should fix represent handler of bool type instead. I guess something like Boolean(object) ? "true" : "false" should fix the issue.

@timreichen
Copy link
Contributor Author

This changes the result of stringify({ foo: new Boolean(true) }) to foo: {} instead of foo: true. I don't think this matches the expectation of the users.

I think we should fix represent handler of bool type instead. I guess something like Boolean(object) ? "true" : "false" should fix the issue.

The problem is that this special treats the Boolean object instance. We have the same problem with

stringify({ foo: new String("foo") })

which returns

foo:
  '0': f
  '1': o
  '2': o

and

stringify({ foo: new Number(1) })

which returns

foo: {}

@timreichen
Copy link
Contributor Author

Tbh, I don't know if we should special treat these cases as they should be discouraged anyway.

@kt3k
Copy link
Member

kt3k commented Sep 3, 2024

The problem is that this special treats the Boolean object instance. We have the same problem with

stringify({ foo: new String("foo") })

which returns

foo:
  '0': f
  '1': o
  '2': o

and

stringify({ foo: new Number(1) })

which returns

foo: {}

Those examples also seem bugs to me.

std/yaml is originally ported from js-yaml and js-yaml handles those cases as foo: foo and foo: 1.

import * as yaml from "npm:js-yaml";

console.log(yaml.dump({ foo: new String("foo") }));
console.log(yaml.dump({ foo: new Number(1) }));

@kt3k
Copy link
Member

kt3k commented Sep 3, 2024

Looks like those handlings of new String and new Number are regression in recent versions. It used to be handled as string and number:

import { stringify } from "https://deno.land/std@0.224.0/yaml/mod.ts";

console.log(stringify({ foo: new String("foo") }));
console.log(stringify({ foo: new Number(1) }));

This prints:

foo: foo
foo: 1

@timreichen
Copy link
Contributor Author

Closing in favour of #5894

@timreichen timreichen closed this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

yaml bool type inconsistent boolean instance evaluation
3 participants