denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.2k stars 621 forks source link

`yaml` bool type inconsistent boolean instance evaluation #5857

Open timreichen opened 2 months ago

timreichen commented 2 months ago

Describe the bug In yaml/_types/bool.ts, booleans are evaluated as

typeof value === "boolean" || value instanceof Boolean

This means Boolean instances are handled as booleans in yaml but the representation is evaluated as

represent: {
    lowercase(object: boolean): string {
      return object ? "true" : "false";
    },
    uppercase(object: boolean): string {
      return object ? "TRUE" : "FALSE";
    },
    camelcase(object: boolean): string {
      return object ? "True" : "False";
    },
}

This will always stringify Boolean instances to "true", which is probably not the intended behavior.

Steps to Reproduce

import { stringify } from "@std/yaml";
import { assertEquals } from "@std/assert";
assertEquals(stringify(new Boolean(false)), "true\n");

Expected behavior new Boolean(false) should evaluate to "false" OR Boolean instances should not be special treated and value instanceof Boolean removed so they are handled as objects.

I am leaning torwards the removal. WDYT?

iuioiua commented 2 months ago

Yeah, it seems the predicate should just be value === true || value === false. I don't see why Boolean instances should be treated in any special way. I'm not aware of any such treatment elsewhere in the codebase.

timreichen commented 2 months ago

I'll open a PR. Would that be breaking or fix?