Skip to content

Commit

Permalink
Apply changes proposed in this [PR](xeipuuv#302) to fix the date-time…
Browse files Browse the repository at this point in the history
… format being too permissive
  • Loading branch information
floriantz committed Jun 11, 2021
1 parent b076d39 commit 7460515
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 0 additions & 3 deletions format_checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ func (f DateTimeFormatChecker) IsFormat(input interface{}) bool {
}

formats := []string{
"15:04:05",
"15:04:05Z07:00",
"2006-01-02",
time.RFC3339,
time.RFC3339Nano,
}
Expand Down
10 changes: 10 additions & 0 deletions format_checkers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ func TestURIReferenceFormatCheckerIsFormat(t *testing.T) {
assert.True(t, checker.IsFormat("https://dummyhost.com/dummy-path?dummy-qp-name=dummy-qp-value"))
}

func TestDateTimeFormatCheckerIsFormat(t *testing.T) {
checker := DateTimeFormatChecker{}

assert.False(t, checker.IsFormat("2019-01-01"))
assert.False(t, checker.IsFormat("2019-01-01 10:00:00"))
assert.False(t, checker.IsFormat("2019-01-01T10:00:00"))
assert.True(t, checker.IsFormat("2019-01-01T10:00:00Z"))
assert.True(t, checker.IsFormat("2019-01-01T10:00:00.102Z"))
}

const formatSchema = `{
"type": "object",
"properties": {
Expand Down
5 changes: 5 additions & 0 deletions testdata/draft7/optional/format/date-time.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"description": "only RFC3339 not all of ISO 8601 are valid",
"data": "2013-350T01:01:01",
"valid": false
},
{
"description": "an invalid date-time string",
"data": "2020-01-01",
"valid": false
}
]
}
Expand Down

0 comments on commit 7460515

Please sign in to comment.