qri-io / jsonschema

golang implementation of https://json-schema.org drafts 7 & 2019-09
MIT License
461 stars 54 forks source link

MinLength Keyword Validation showing a wrong error message #84

Closed pgioino closed 3 years ago

pgioino commented 4 years ago
func (m MinLength) ValidateKeyword(ctx context.Context, currentState *ValidationState, data interface{}) {
    schemaDebug("[MinLength] Validating")
    if str, ok := data.(string); ok {
        if utf8.RuneCountInString(str) < int(m) {
            currentState.AddError(data, fmt.Sprintf("max length of %d characters exceeded: %s", m, str))
        }
    }
}

The error message is probably a copy/paste of the MaxLength Keyword Validation Should be something like: currentState.AddError(data, fmt.Sprintf("'%s' does not match minimum length of %d", str, m))

peterhellberg commented 3 years ago

I also noticed this issue just now. Would a PR help with getting this fixed?

Arqu commented 3 years ago

Absolutely, PRs are always welcome. Thank you.

peterhellberg commented 3 years ago

@Arqu I forked the repo and noticed that this error has been fixed in 0995c6b04506cc858dee03b166771edeeab95f64 (https://github.com/qri-io/jsonschema/pull/73)

So what is needed is a new tagged release :)

Arqu commented 3 years ago

My bad then, sorry. There's definitely some clean up I need to do. I'll aim to tag a release in the near term. Might want to include a few more fixes if possible. I'll close this out for now. A temporary workaround is to pin the specific commit.