corvus_json_schema 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.lock +2 -2
- data/THIRD-PARTY-NOTICES.txt +7 -0
- data/VERSIONHISTORY.md +4 -0
- data/ext/corvus_json_schema/Cargo.toml +2 -2
- data/ext/corvus_json_schema/vendor/corvus-json-schema/Cargo.toml +2 -2
- data/ext/corvus_json_schema/vendor/corvus-json-schema/README.md +4 -0
- data/ext/corvus_json_schema/vendor/corvus-json-schema/src/formats.rs +136 -34
- data/lib/corvus_json_schema/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2d6d62a0eb2cb819fe949d079da714047ce1bb5ee695d246af0ce03950abfcd
|
|
4
|
+
data.tar.gz: 82520c447c8428446fbc09a5cbdef0fe2f816e7625892746787d2bf482273ffc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4af037fa1e379e6dd1d7485d489a801bee5dca0ce12d27e3f898030cdacefc722707710b186650b0931c361e3972302f9093cdc8f5634703cb31ee7009985f91
|
|
7
|
+
data.tar.gz: cd508042b291cb40084fdd5d39980775d7af2b428a36936d1e7b8e1f70079a3ffa61cb59a570298af467f7f31827afe98b1339839c3ee22618cee8b6c869b052
|
data/Cargo.lock
CHANGED
|
@@ -63,7 +63,7 @@ dependencies = [
|
|
|
63
63
|
|
|
64
64
|
[[package]]
|
|
65
65
|
name = "corvus-json-schema"
|
|
66
|
-
version = "0.2.
|
|
66
|
+
version = "0.2.2"
|
|
67
67
|
dependencies = [
|
|
68
68
|
"corvus-regex-ecma262",
|
|
69
69
|
"regex",
|
|
@@ -82,7 +82,7 @@ dependencies = [
|
|
|
82
82
|
|
|
83
83
|
[[package]]
|
|
84
84
|
name = "corvus_json_schema"
|
|
85
|
-
version = "0.2.
|
|
85
|
+
version = "0.2.2"
|
|
86
86
|
dependencies = [
|
|
87
87
|
"corvus-json-schema",
|
|
88
88
|
"magnus",
|
data/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -11,6 +11,13 @@ The attached notices are provided for information only.
|
|
|
11
11
|
License notice for the Unicode Character Database
|
|
12
12
|
-------------------------------
|
|
13
13
|
|
|
14
|
+
src/uts46_data.rs of the corvus-json-schema crate holds a table derived from
|
|
15
|
+
IdnaMappingTable.txt of Unicode 17.0.0
|
|
16
|
+
(https://www.unicode.org/Public/17.0.0/idna/IdnaMappingTable.txt), the data of
|
|
17
|
+
UTS #46, Unicode IDNA Compatibility Processing: the code points it maps or
|
|
18
|
+
ignores, and their mappings. That data file is licensed under the Unicode
|
|
19
|
+
License V3, as the data files below are.
|
|
20
|
+
|
|
14
21
|
The gem is built on the corvus-json-schema Rust crate. The source gem holds
|
|
15
22
|
the crate's sources (ext/corvus_json_schema/vendor/corvus-json-schema), and a
|
|
16
23
|
native gem holds the extension compiled from them. That crate matches patterns
|
data/VERSIONHISTORY.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
The version history of the `corvus_json_schema` Ruby gem. It is versioned independently of the Corvus NuGet packages and of the [corvus-json-schema](../../src-rs/corvus-json-schema/VERSIONHISTORY.md) Rust crate it is built on.
|
|
4
4
|
|
|
5
|
+
## V0.2.2
|
|
6
|
+
|
|
7
|
+
V0.2.2 takes version 0.2.2 of the `corvus-json-schema` crate, which fixes leap seconds in the `date-time` format. `date-time` accepts a leap second (23:59:60 UTC) only on the 27 days that the IERS has ended with one, from 1972-06-30 to 2016-12-31, in whatever offset the value is written (`1998-12-31T15:59:60-08:00` is valid, `1999-12-31T23:59:60Z` is not). It accepted 23:59:60 UTC on any day. `time` is unchanged: it has no date, so it accepts a leap second whenever the time is 23:59 in UTC. Nothing else in the gem changes.
|
|
8
|
+
|
|
5
9
|
## V0.2.1
|
|
6
10
|
|
|
7
11
|
V0.2.1 takes version 0.2.1 of the `corvus-json-schema` crate, which fixes the `format` checks that the JSON-Schema-Test-Suite's unified layout found wrong. `idn-hostname` (and the domain of `idn-email`) applies the UTS #46 mapping (Unicode 17.0.0) before it checks a name, so ignored code points such as U+200B are removed and fullwidth letters are read as ASCII. `email` follows RFC 5321 in a quoted local part (printable ASCII and quoted pairs of printable ASCII only), and `idn-email` RFC 6531 (any character outside ASCII in the local part, whatever its category). `uri-template` takes the RFC 6570 literals, with the apostrophe that erratum 6937 adds, so a `%` must begin a complete percent-encoded triplet and a delete character is refused. Nothing else in the gem changes.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "corvus_json_schema"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.89"
|
|
6
6
|
description = "The native extension of the corvus_json_schema gem: the corvus-json-schema crate, reading Ruby values in place."
|
|
@@ -12,7 +12,7 @@ crate-type = ["cdylib"]
|
|
|
12
12
|
|
|
13
13
|
[dependencies]
|
|
14
14
|
# The crate, copied in by `rake vendor` (from src-rs/corvus-json-schema) so that the source gem builds on its own.
|
|
15
|
-
corvus = { package = "corvus-json-schema", path = "vendor/corvus-json-schema", version = "0.2.
|
|
15
|
+
corvus = { package = "corvus-json-schema", path = "vendor/corvus-json-schema", version = "0.2.2" }
|
|
16
16
|
magnus = { version = "0.9.1", features = ["rb-sys"] }
|
|
17
17
|
rb-sys = "0.9.130"
|
|
18
18
|
serde_json = { version = "1.0.151", features = ["preserve_order", "float_roundtrip"] }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "corvus-json-schema"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.89"
|
|
6
6
|
description = "A high-performance JSON Schema evaluator (draft 4 to 2020-12) with results collection and annotations, ported from the Corvus.Text.Json V5 runtime evaluator."
|
|
@@ -14,7 +14,7 @@ categories = ["encoding", "parser-implementations"]
|
|
|
14
14
|
# The published crate: the library and its documents. The tests read the repository's JSON-Schema-Test-Suite
|
|
15
15
|
# submodule and the C# metaschemas, so they only run from a checkout. LICENSE is a copy of the repository's (CI checks
|
|
16
16
|
# it matches).
|
|
17
|
-
include = ["src/**", "Cargo.toml", "README.md", "LICENSE"]
|
|
17
|
+
include = ["src/**", "Cargo.toml", "README.md", "LICENSE", "THIRD-PARTY-NOTICES.txt"]
|
|
18
18
|
|
|
19
19
|
[dependencies]
|
|
20
20
|
corvus-regex-ecma262 = "0.2.7"
|
|
@@ -201,3 +201,7 @@ This runs:
|
|
|
201
201
|
## License
|
|
202
202
|
|
|
203
203
|
Apache 2.0.
|
|
204
|
+
|
|
205
|
+
`src/uts46_data.rs` holds a table derived from the UTS #46 IDNA mapping data of Unicode 17.0.0, which is under the
|
|
206
|
+
Unicode License V3. [THIRD-PARTY-NOTICES.txt](THIRD-PARTY-NOTICES.txt), which the published crate holds, has that
|
|
207
|
+
notice. `corvus-regex-ecma262` carries the notices of the tables it holds.
|
|
@@ -275,26 +275,32 @@ fn digits(s: &[u8]) -> Option<u32> {
|
|
|
275
275
|
Some(s.iter().fold(0u32, |a, &b| a * 10 + (b - b'0') as u32))
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
|
|
278
|
+
/// Reads an RFC 3339 `full-date`, checking that the day is in the month.
|
|
279
|
+
fn date_parts(s: &str) -> Option<(u32, u32, u32)> {
|
|
279
280
|
let b = s.as_bytes();
|
|
280
281
|
if b.len() != 10 || b[4] != b'-' || b[7] != b'-' {
|
|
281
|
-
return
|
|
282
|
+
return None;
|
|
282
283
|
}
|
|
283
|
-
let (
|
|
284
|
-
return false;
|
|
285
|
-
};
|
|
284
|
+
let (y, m, d) = (digits(&b[0..4])?, digits(&b[5..7])?, digits(&b[8..10])?);
|
|
286
285
|
const DAYS: [u32; 13] = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
287
|
-
(1..=12).contains(&m) && d >= 1 && d <= if m == 2 && is_leap_year(y) { 29 } else { DAYS[m as usize] }
|
|
286
|
+
((1..=12).contains(&m) && d >= 1 && d <= if m == 2 && is_leap_year(y) { 29 } else { DAYS[m as usize] })
|
|
287
|
+
.then_some((y, m, d))
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
pub(crate) fn
|
|
291
|
-
|
|
290
|
+
pub(crate) fn date(s: &str) -> bool {
|
|
291
|
+
date_parts(s).is_some()
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const MINUTES_PER_DAY: i32 = 24 * 60;
|
|
295
|
+
const LAST_MINUTE_OF_DAY: i32 = MINUTES_PER_DAY - 1;
|
|
296
|
+
|
|
297
|
+
/// Reads an RFC 3339 `full-time`: the second (up to 60), and the minute of the time in UTC counted from the start of
|
|
298
|
+
/// the day it is written in, which runs from -1439 (the day before) to 2878 (the day after).
|
|
299
|
+
fn full_time(b: &[u8]) -> Option<(u32, i32)> {
|
|
292
300
|
if b.len() < 9 || b[2] != b':' || b[5] != b':' {
|
|
293
|
-
return
|
|
301
|
+
return None;
|
|
294
302
|
}
|
|
295
|
-
let (
|
|
296
|
-
return false;
|
|
297
|
-
};
|
|
303
|
+
let (h, mi, sec) = (digits(&b[0..2])?, digits(&b[3..5])?, digits(&b[6..8])?);
|
|
298
304
|
let mut i = 8;
|
|
299
305
|
if b[i] == b'.' {
|
|
300
306
|
i += 1;
|
|
@@ -303,49 +309,109 @@ pub(crate) fn time(s: &str) -> bool {
|
|
|
303
309
|
i += 1;
|
|
304
310
|
}
|
|
305
311
|
if i == start {
|
|
306
|
-
return
|
|
312
|
+
return None;
|
|
307
313
|
}
|
|
308
314
|
}
|
|
309
315
|
if i >= b.len() {
|
|
310
|
-
return
|
|
316
|
+
return None;
|
|
311
317
|
}
|
|
312
|
-
let
|
|
318
|
+
let mut offset = 0i32;
|
|
313
319
|
match b[i] {
|
|
314
320
|
b'z' | b'Z' => {
|
|
315
321
|
if i + 1 != b.len() {
|
|
316
|
-
return
|
|
322
|
+
return None;
|
|
317
323
|
}
|
|
318
324
|
}
|
|
319
325
|
b'+' | b'-' => {
|
|
320
326
|
if b.len() - i != 6 || b[i + 3] != b':' {
|
|
321
|
-
return
|
|
327
|
+
return None;
|
|
322
328
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
+
let (oh, om) = (digits(&b[i + 1..i + 3])?, digits(&b[i + 4..i + 6])?);
|
|
330
|
+
if oh > 23 || om > 59 {
|
|
331
|
+
return None;
|
|
332
|
+
}
|
|
333
|
+
offset = (oh * 60 + om) as i32;
|
|
334
|
+
if b[i] == b'+' {
|
|
335
|
+
offset = -offset;
|
|
329
336
|
}
|
|
330
|
-
oh = x;
|
|
331
|
-
om = y;
|
|
332
337
|
}
|
|
333
|
-
_ => return
|
|
338
|
+
_ => return None,
|
|
334
339
|
}
|
|
335
340
|
if h > 23 || mi > 59 || sec > 60 {
|
|
336
|
-
return
|
|
337
|
-
}
|
|
338
|
-
if sec == 60 {
|
|
339
|
-
// A leap second is only valid at 23:59:60 UTC.
|
|
340
|
-
let utc = (h * 60 + mi) as i32 + sign * (oh * 60 + om) as i32;
|
|
341
|
-
return utc.rem_euclid(1440) == 23 * 60 + 59;
|
|
341
|
+
return None;
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
Some((sec, (h * 60 + mi) as i32 + offset))
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
+
pub(crate) fn time(s: &str) -> bool {
|
|
347
|
+
// A time has no date, so a leap second is valid whenever it is 23:59 in UTC.
|
|
348
|
+
full_time(s.as_bytes()).is_some_and(|(sec, utc)| sec < 60 || utc.rem_euclid(MINUTES_PER_DAY) == LAST_MINUTE_OF_DAY)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/// The number of days from 1970-01-01 to a date in the proleptic Gregorian calendar (Howard Hinnant's algorithm).
|
|
352
|
+
const fn days_from_civil(year: i32, month: i32, day: i32) -> i32 {
|
|
353
|
+
let y = if month <= 2 { year - 1 } else { year };
|
|
354
|
+
let era = y.div_euclid(400);
|
|
355
|
+
let year_of_era = y - era * 400;
|
|
356
|
+
let day_of_year = (153 * (month + if month > 2 { -3 } else { 9 }) + 2) / 5 + day - 1;
|
|
357
|
+
let day_of_era = year_of_era * 365 + year_of_era / 4 - year_of_era / 100 + day_of_year;
|
|
358
|
+
era * 146_097 + day_of_era - 719_468
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/// The days that the IERS has ended with a positive leap second (23:59:60 UTC), from 1972-06-30 to 2016-12-31.
|
|
362
|
+
const LEAP_SECOND_DAYS: [i32; 27] = {
|
|
363
|
+
const DATES: [(i32, i32, i32); 27] = [
|
|
364
|
+
(1972, 6, 30),
|
|
365
|
+
(1972, 12, 31),
|
|
366
|
+
(1973, 12, 31),
|
|
367
|
+
(1974, 12, 31),
|
|
368
|
+
(1975, 12, 31),
|
|
369
|
+
(1976, 12, 31),
|
|
370
|
+
(1977, 12, 31),
|
|
371
|
+
(1978, 12, 31),
|
|
372
|
+
(1979, 12, 31),
|
|
373
|
+
(1981, 6, 30),
|
|
374
|
+
(1982, 6, 30),
|
|
375
|
+
(1983, 6, 30),
|
|
376
|
+
(1985, 6, 30),
|
|
377
|
+
(1987, 12, 31),
|
|
378
|
+
(1989, 12, 31),
|
|
379
|
+
(1990, 12, 31),
|
|
380
|
+
(1992, 6, 30),
|
|
381
|
+
(1993, 6, 30),
|
|
382
|
+
(1994, 6, 30),
|
|
383
|
+
(1995, 12, 31),
|
|
384
|
+
(1997, 6, 30),
|
|
385
|
+
(1998, 12, 31),
|
|
386
|
+
(2005, 12, 31),
|
|
387
|
+
(2008, 12, 31),
|
|
388
|
+
(2012, 6, 30),
|
|
389
|
+
(2015, 6, 30),
|
|
390
|
+
(2016, 12, 31),
|
|
391
|
+
];
|
|
392
|
+
let mut days = [0; 27];
|
|
393
|
+
let mut i = 0;
|
|
394
|
+
while i < 27 {
|
|
395
|
+
days[i] = days_from_civil(DATES[i].0, DATES[i].1, DATES[i].2);
|
|
396
|
+
i += 1;
|
|
397
|
+
}
|
|
398
|
+
days
|
|
399
|
+
};
|
|
400
|
+
|
|
346
401
|
pub(crate) fn date_time(s: &str) -> bool {
|
|
347
402
|
let b = s.as_bytes();
|
|
348
|
-
b.len()
|
|
403
|
+
if b.len() <= 11 || !(b[10] == b'T' || b[10] == b't') || !s.is_char_boundary(10) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
let (Some((y, m, d)), Some((sec, utc))) = (date_parts(&s[..10]), full_time(&b[11..])) else {
|
|
407
|
+
return false;
|
|
408
|
+
};
|
|
409
|
+
// A leap second is valid only at 23:59:60 UTC on a day that ended with one, which may be the day before or after
|
|
410
|
+
// the date as written.
|
|
411
|
+
sec < 60
|
|
412
|
+
|| utc.rem_euclid(MINUTES_PER_DAY) == LAST_MINUTE_OF_DAY
|
|
413
|
+
&& LEAP_SECOND_DAYS
|
|
414
|
+
.contains(&(days_from_civil(y as i32, m as i32, d as i32) + utc.div_euclid(MINUTES_PER_DAY)))
|
|
349
415
|
}
|
|
350
416
|
|
|
351
417
|
static DURATION_RE: LazyLock<Regex> = LazyLock::new(|| {
|
|
@@ -954,6 +1020,42 @@ mod tests {
|
|
|
954
1020
|
assert!(date("2020-02-29") && !date("2021-02-29"));
|
|
955
1021
|
assert!(time("23:59:60Z") && !time("22:59:60Z") && time("08:30:06.283185+01:00"));
|
|
956
1022
|
assert!(date_time("1963-06-19T08:30:06.283185Z") && !date_time("1963-06-19 08:30:06Z"));
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
#[test]
|
|
1026
|
+
fn leap_seconds() {
|
|
1027
|
+
// date-time: 23:59:60 UTC, only on a day that ended with a leap second, in whatever offset it is written.
|
|
1028
|
+
for (text, expected) in [
|
|
1029
|
+
("1998-12-31T23:59:60Z", true),
|
|
1030
|
+
("1998-12-31T15:59:60.123-08:00", true),
|
|
1031
|
+
("1972-06-30T23:59:60Z", true),
|
|
1032
|
+
("2016-12-31T23:59:60z", true),
|
|
1033
|
+
("2017-01-01T00:59:60+01:00", true),
|
|
1034
|
+
("1998-12-31T00:29:60-23:30", true),
|
|
1035
|
+
("1999-01-01T00:29:60+00:30", true),
|
|
1036
|
+
("1998-12-30T23:59:60-24:00", false),
|
|
1037
|
+
("1998-12-31T23:59:60+00:00", true),
|
|
1038
|
+
("1999-12-31T23:59:60Z", false),
|
|
1039
|
+
("2017-12-31T23:59:60Z", false),
|
|
1040
|
+
("1998-12-31T23:58:60Z", false),
|
|
1041
|
+
("1998-12-31T22:59:60Z", false),
|
|
1042
|
+
("1998-12-31T23:59:61Z", false),
|
|
1043
|
+
("2016-12-31T22:59:60-01:00", true),
|
|
1044
|
+
("2016-12-30T23:59:60-24:00", false),
|
|
1045
|
+
("2016-12-31T00:00:60Z", false),
|
|
1046
|
+
("1998-12-31T23:59:60+23:59", false),
|
|
1047
|
+
("1999-01-01T23:58:60+23:59", true),
|
|
1048
|
+
("1998-12-31T00:00:60-23:59", true),
|
|
1049
|
+
] {
|
|
1050
|
+
assert_eq!(date_time(text), expected, "{text}");
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// time: 23:59:60 in UTC, on any day.
|
|
1054
|
+
for (text, expected) in
|
|
1055
|
+
[("23:59:60Z", true), ("15:59:60-08:00", true), ("00:29:60-23:30", true), ("23:58:60Z", false)]
|
|
1056
|
+
{
|
|
1057
|
+
assert_eq!(time(text), expected, "{text}");
|
|
1058
|
+
}
|
|
957
1059
|
assert!(ipv6("::ffff:192.168.0.1") && !ipv6("1:2:3:4:5:6:7:8:9"));
|
|
958
1060
|
assert!(hostname("xn--4gbwdl.xn--wgbh1c") && !hostname("-a.com"));
|
|
959
1061
|
assert!(idn_hostname("실례.테스트") && !idn_hostname("〮실례.테스트"));
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: corvus_json_schema
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- endjin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rb_sys
|