Skip to content

@std/ini: options.reviver value is not type casted #6884

@timreichen

Description

@timreichen

Describe the bug
The reviver() fn does not receive type cast values. This behavior differs from JSON.parse().
I think this might should be adjusted.

import { parse } from "jsr:@std/ini/parse"
import { assertEquals } from "jsr:@std/assert/equals"

const expected = { a: 100 }

const json = '{ "a": 100 }'
const parsedJson = JSON.parse(json)
assertEquals(parsedJson, expected)

const ini = "a=100"
const parsedIni = parse(ini)
assertEquals(parsedIni, expected)

but

import { parse } from "jsr:@std/ini/parse"
import { assertEquals } from "jsr:@std/assert/equals"

const expected = { a: 100 }

const json = '{ "a": 100 }'
const parsedJson = JSON.parse(json, (_key, value) => value)
assertEquals(parsedJson, expected)

const ini = "a=100"
const parsedIni = parse(ini, { reviver: (_key, value) => value })
assertEquals(parsedIni, expected) // fails because value is string "100", not number 100.

Steps to Reproduce

import { parse } from "jsr:@std/ini/parse"
import { assertEquals } from "jsr:@std/assert/equals"

const expected = { a: 100 }
const ini = "a=100"
const parsedIni = parse(ini, { reviver: (_key, value) => value })
assertEquals(parsedIni, expected) // fails because value is string "100", not number 100.

Expected behavior

import { parse } from "jsr:@std/ini/parse"
import { assertEquals } from "jsr:@std/assert/equals"

const expected = { a: 100 }
const ini = "a=100"
const parsedIni = parse(ini, { reviver: (_key, value) => value })
assertEquals(parsedIni, expected)

Environment

  • OS: [e.g. Ubuntu 20.04, MacOS 11] MacOS 26.1
  • deno version: 2.5.6
  • std version: ini 1.0.0-rc.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions