Skip to content

Commit

Permalink
Merge pull request #31 from seriousme/fix-multiple-byte-tests
Browse files Browse the repository at this point in the history
Fix multiple byte tests
  • Loading branch information
epoberezkin authored Aug 14, 2021
2 parents df9c29e + 9ad8d8b commit 10669ff
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const fullFormats: DefinedFormats = {
"relative-json-pointer": /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
// the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types
// byte: https://github.com/miguelmota/is-base64
byte: /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,
byte,
// signed 32 bit integer
int32: {type: "number", validate: validateInt32},
// signed 64 bit integer
Expand Down Expand Up @@ -197,6 +197,13 @@ function uri(str: string): boolean {
return NOT_URI_FRAGMENT.test(str) && URI.test(str)
}

const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm

function byte(str: string): boolean {
BYTE.lastIndex = 0
return BYTE.test(str)
}

const MIN_INT32 = -(2 ** 31)
const MAX_INT32 = 2 ** 31 - 1

Expand Down
5 changes: 5 additions & 0 deletions tests/extras/format.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@
"data": "VGhpcyBpcyBhIGJhc2U2NCBtdWx0aWxpbmUgc3RyaW5nIHRoYXQgc3BhbnMgbW9yZSB0aGFuIDc2\nIGNoYXJhY3RlcnMgdG8gdGVzdCBtdWx0aWxpbmUgY2FwYWJpbGl0aWVzCg==",
"valid": true
},
{
"description": "second round multiline base64",
"data": "VGhpcyBpcyBhIGJhc2U2NCBtdWx0aWxpbmUgc3RyaW5nIHRoYXQgc3BhbnMgbW9yZSB0aGFuIDc2\nIGNoYXJhY3RlcnMgdG8gdGVzdCBtdWx0aWxpbmUgY2FwYWJpbGl0aWVzCg==",
"valid": true
},
{
"description": "Invalid base64",
"data": "aGVsbG8gd29ybG=",
Expand Down
2 changes: 1 addition & 1 deletion tests/extras/formatMinimum.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
"valid": false
},
{
"description": "same date, time before the minimum time is stillinvalid",
"description": "same date, time before the minimum time is still invalid",
"data": "2015-08-17T10:33:55.000Z",
"valid": false
},
Expand Down
12 changes: 6 additions & 6 deletions tests/extras/issues/1061_alternative_time_offsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"schema": {"format": "date-time"},
"tests": [
{
"description": "valid positiive two digit",
"description": "valid positive two digit",
"data": "2016-01-31T02:31:17+01",
"valid": true
},
Expand All @@ -14,7 +14,7 @@
"valid": true
},
{
"description": "valid positiive four digit no colon",
"description": "valid positive four digit no colon",
"data": "2016-01-31T02:31:17+0130",
"valid": true
},
Expand All @@ -24,7 +24,7 @@
"valid": true
},
{
"description": "invalid positiive three digit no colon",
"description": "invalid positive three digit no colon",
"data": "2016-01-31T02:31:17+013",
"valid": false
},
Expand All @@ -40,7 +40,7 @@
"schema": {"format": "time"},
"tests": [
{
"description": "valid positiive two digit",
"description": "valid positive two digit",
"data": "02:31:17+01",
"valid": true
},
Expand All @@ -50,7 +50,7 @@
"valid": true
},
{
"description": "valid positiive four digit no colon",
"description": "valid positive four digit no colon",
"data": "02:31:17+0130",
"valid": true
},
Expand All @@ -60,7 +60,7 @@
"valid": true
},
{
"description": "invalid positiive three digit no colon",
"description": "invalid positive three digit no colon",
"data": "02:31:17+013",
"valid": false
},
Expand Down

0 comments on commit 10669ff

Please sign in to comment.