Skip to content

Commit 10669ff

Browse files
authored
Merge pull request #31 from seriousme/fix-multiple-byte-tests
Fix multiple byte tests
2 parents df9c29e + 9ad8d8b commit 10669ff

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/formats.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const fullFormats: DefinedFormats = {
7575
"relative-json-pointer": /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
7676
// the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types
7777
// byte: https://github.com/miguelmota/is-base64
78-
byte: /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,
78+
byte,
7979
// signed 32 bit integer
8080
int32: {type: "number", validate: validateInt32},
8181
// signed 64 bit integer
@@ -197,6 +197,13 @@ function uri(str: string): boolean {
197197
return NOT_URI_FRAGMENT.test(str) && URI.test(str)
198198
}
199199

200+
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm
201+
202+
function byte(str: string): boolean {
203+
BYTE.lastIndex = 0
204+
return BYTE.test(str)
205+
}
206+
200207
const MIN_INT32 = -(2 ** 31)
201208
const MAX_INT32 = 2 ** 31 - 1
202209

tests/extras/format.json

+5
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=",

tests/extras/formatMinimum.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"valid": false
180180
},
181181
{
182-
"description": "same date, time before the minimum time is stillinvalid",
182+
"description": "same date, time before the minimum time is still invalid",
183183
"data": "2015-08-17T10:33:55.000Z",
184184
"valid": false
185185
},

tests/extras/issues/1061_alternative_time_offsets.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"schema": {"format": "date-time"},
55
"tests": [
66
{
7-
"description": "valid positiive two digit",
7+
"description": "valid positive two digit",
88
"data": "2016-01-31T02:31:17+01",
99
"valid": true
1010
},
@@ -14,7 +14,7 @@
1414
"valid": true
1515
},
1616
{
17-
"description": "valid positiive four digit no colon",
17+
"description": "valid positive four digit no colon",
1818
"data": "2016-01-31T02:31:17+0130",
1919
"valid": true
2020
},
@@ -24,7 +24,7 @@
2424
"valid": true
2525
},
2626
{
27-
"description": "invalid positiive three digit no colon",
27+
"description": "invalid positive three digit no colon",
2828
"data": "2016-01-31T02:31:17+013",
2929
"valid": false
3030
},
@@ -40,7 +40,7 @@
4040
"schema": {"format": "time"},
4141
"tests": [
4242
{
43-
"description": "valid positiive two digit",
43+
"description": "valid positive two digit",
4444
"data": "02:31:17+01",
4545
"valid": true
4646
},
@@ -50,7 +50,7 @@
5050
"valid": true
5151
},
5252
{
53-
"description": "valid positiive four digit no colon",
53+
"description": "valid positive four digit no colon",
5454
"data": "02:31:17+0130",
5555
"valid": true
5656
},
@@ -60,7 +60,7 @@
6060
"valid": true
6161
},
6262
{
63-
"description": "invalid positiive three digit no colon",
63+
"description": "invalid positive three digit no colon",
6464
"data": "02:31:17+013",
6565
"valid": false
6666
},

0 commit comments

Comments
 (0)