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

Validator incorrectly accepts strings for booleans #86

Open
polarina opened this issue Nov 9, 2020 · 0 comments
Open

Validator incorrectly accepts strings for booleans #86

polarina opened this issue Nov 9, 2020 · 0 comments

Comments

@polarina
Copy link

polarina commented Nov 9, 2020

Hi,

The JSON schema validator incorrectly accepts the JSON strings "true" and "false" for booleans.

Example schema:

{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "type": "boolean"
}

Example input:

"true"

Expected error:

/: "true" type should be boolean, got string

Observed behaviour:
Validation passes without errors, which was not expected.

Program:

package main

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/qri-io/jsonschema"
)

func main() {
	ctx := context.Background()
	var schemaData = []byte(`{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "type": "boolean"
  }`)

	rs := &jsonschema.Schema{}
	if err := json.Unmarshal(schemaData, rs); err != nil {
		panic("unmarshal schema: " + err.Error())
	}

	var invalid = []byte(`"true"`)
	errs, err := rs.ValidateBytes(ctx, invalid)
	if err != nil {
		panic(err)
	}

	if len(errs) > 0 {
		fmt.Println(errs[0].Error())
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant