Skip to content

Commit 4d10bcf

Browse files
committed
Fix multiple byte tests
1 parent b868686 commit 4d10bcf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/formats.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const fullFormats: DefinedFormats = {
7171
"relative-json-pointer": /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
7272
// the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types
7373
// byte: https://github.com/miguelmota/is-base64
74-
byte: /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,
74+
byte,
7575
// signed 32 bit integer
7676
int32: {type: "number", validate: validateInt32},
7777
// signed 64 bit integer
@@ -191,6 +191,11 @@ function uri(str: string): boolean {
191191
return NOT_URI_FRAGMENT.test(str) && URI.test(str)
192192
}
193193

194+
function byte(str: string): boolean {
195+
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm
196+
return BYTE.test(str)
197+
}
198+
194199
const MIN_INT32 = -(2 ** 31)
195200
const MAX_INT32 = 2 ** 31 - 1
196201

tests/extras/format.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@
743743
"data": "VGhpcyBpcyBhIGJhc2U2NCBtdWx0aWxpbmUgc3RyaW5nIHRoYXQgc3BhbnMgbW9yZSB0aGFuIDc2\nIGNoYXJhY3RlcnMgdG8gdGVzdCBtdWx0aWxpbmUgY2FwYWJpbGl0aWVzCg==",
744744
"valid": true
745745
},
746+
{
747+
"description": "second round multiline base64",
748+
"data": "VGhpcyBpcyBhIGJhc2U2NCBtdWx0aWxpbmUgc3RyaW5nIHRoYXQgc3BhbnMgbW9yZSB0aGFuIDc2\nIGNoYXJhY3RlcnMgdG8gdGVzdCBtdWx0aWxpbmUgY2FwYWJpbGl0aWVzCg==",
749+
"valid": true
750+
},
746751
{
747752
"description": "Invalid base64",
748753
"data": "aGVsbG8gd29ybG=",

0 commit comments

Comments
 (0)