Skip to content

x.json: string to number cast, not following JSON specfications #26082

@enghitalo

Description

@enghitalo

Describe the bug

Tests like vlib/x/json2/tests/decode_budget_number_test.v are supporting string cast

Reproduction Steps

import x.json2 as json

fn test_budget_number() {
	assert json.decode[int]('"0"')! == 0
	assert json.decode[int]('"100"')! == 100
	assert json.decode[f64]('"-23.6e1"')! == -236.0

	assert json.decode[[]int]('["100", 99, "98", 97]')! == [100, 99, 98, 97]
}

fn test_budget_number_malformed() {
	json.decode[int]('"+100"') or {
		if err is json.JsonDecodeError {
			assert err.line == 1
			assert err.character == 2
			assert err.message == 'Syntax: expected digit got +'
		}

		return
	}

	assert false
}

Expected Behavior

json check error

Current Behavior

asset pass

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12 07331bd

Environment details (OS name and version, etc.)

Linux

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions