Skip to content

Commit

Permalink
Fix multiple byte tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousme committed May 12, 2021
1 parent b868686 commit 4d10bcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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 @@ -191,6 +191,11 @@ function uri(str: string): boolean {
return NOT_URI_FRAGMENT.test(str) && URI.test(str)
}

function byte(str: string): boolean {
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm
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

0 comments on commit 4d10bcf

Please sign in to comment.