From 5c2918fa2f2ed28b3167dc3276203a8aa4d69419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Mari=CC=81a=20Marti=CC=81n?= Date: Fri, 8 Oct 2021 07:33:10 +0200 Subject: [PATCH] Do not escape regular expressions again (getkin#429) The string representing the regular expression is already escaped, using '%q' escapes it again, resulting in the wrong regex being displayed. --- openapi3/schema.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openapi3/schema.go b/openapi3/schema.go index de3e5167d..5f1ee60b4 100644 --- a/openapi3/schema.go +++ b/openapi3/schema.go @@ -1167,7 +1167,7 @@ func (schema *Schema) visitJSONString(settings *schemaValidationSettings, value Value: value, Schema: schema, SchemaField: "pattern", - Reason: fmt.Sprintf("string doesn't match the regular expression %q", schema.Pattern), + Reason: fmt.Sprintf("string doesn't match the regular expression \"%s\"", schema.Pattern), } if !settings.multiError { return err @@ -1182,7 +1182,7 @@ func (schema *Schema) visitJSONString(settings *schemaValidationSettings, value switch { case f.regexp != nil && f.callback == nil: if cp := f.regexp; !cp.MatchString(value) { - formatErr = fmt.Sprintf("string doesn't match the format %q (regular expression %q)", format, cp.String()) + formatErr = fmt.Sprintf("string doesn't match the format %q (regular expression \"%s\")", format, cp.String()) } case f.regexp == nil && f.callback != nil: if err := f.callback(value); err != nil {