Skip to content

Commit b603aaa

Browse files
authored
Merge pull request #54 from swaggest/update-test-suite
update JSON-Schema-Test-Suite, AJV test suite and fix failed tests
2 parents 87b25f8 + 1228ba8 commit b603aaa

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

spec/ajv

Submodule ajv updated from 2726d29 to 88d57fa

src/Constraint/Format.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Format
2626
const IRI_REFERENCE = 'iri-reference';
2727
const URI_TEMPLATE = 'uri-template';
2828

29+
public static $strictDateTimeValidation = false;
30+
2931
private static $dateRegexPart = '(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])';
3032
private static $timeRegexPart = '([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))?';
3133
private static $jsonPointerRegex = '_^(?:/|(?:/[^/#]*)*)$_';
@@ -75,9 +77,26 @@ public static function validationError($format, $data)
7577

7678
public static function dateTimeError($data)
7779
{
78-
return preg_match('/^' . self::$dateRegexPart . 'T' . self::$timeRegexPart . '$/i', $data)
79-
? null
80-
: 'Invalid date-time: ' . $data;
80+
if (!preg_match('/^' . self::$dateRegexPart . 'T' . self::$timeRegexPart . '$/i', $data)) {
81+
return 'Invalid date-time format: ' . $data;
82+
}
83+
84+
if (self::$strictDateTimeValidation) {
85+
$dt = date_create($data);
86+
if ($dt === false) {
87+
return 'Failed to parse date-time: ' . $data;
88+
}
89+
$isLeapSecond = '6' === $data[17] && (
90+
0 === strpos(substr($data, 5, 5), '12-31') ||
91+
0 === strpos(substr($data, 5, 5), '06-30')
92+
);
93+
if (!$isLeapSecond &&
94+
0 !== stripos($dt->format(DATE_RFC3339), substr($data, 0, 19))) {
95+
return 'Invalid date-time value: ' . $data;
96+
}
97+
}
98+
99+
return null;
81100
}
82101

83102
public static function regexError($data)

src/Constraint/UniqueItems.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ public static function isValid(array $data)
1717
foreach ($data as $value) {
1818
if (is_array($value) || $value instanceof \stdClass) {
1919
$value = json_encode($value);
20-
}
21-
if (is_bool($value)) {
22-
$value = '_______BOOL' . $value;
23-
}
24-
if ($value instanceof ObjectItemContract) {
20+
} elseif (is_bool($value)) {
21+
$value = '_B' . $value;
22+
} elseif (is_string($value)) {
23+
$value = '_S' . $value;
24+
} elseif (is_int($value)) {
25+
$value = '_I' . $value;
26+
} elseif (is_float($value)) {
27+
$value = '_F' . $value;
28+
} elseif ($value instanceof ObjectItemContract) {
2529
$value = json_encode($value);
2630
}
2731
$tmp = &$index[$value];

src/Schema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,9 @@ public function process($data, Context $options, $path = '#', $result = null)
11441144
}
11451145

11461146
if ($this->contentEncoding !== null || $this->contentMediaType !== null) {
1147+
if ($import && !is_string($data)) {
1148+
return $result;
1149+
}
11471150
$result = $this->processContent($data, $options, $path);
11481151
}
11491152

tests/src/PHPUnit/Spec/SchemaTestSuite.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Swaggest\JsonSchema\Tests\PHPUnit\Spec;
44

5+
use Swaggest\JsonSchema\Constraint\Format;
56
use Swaggest\JsonSchema\Context;
67
use Swaggest\JsonSchema\InvalidValue;
78
use Swaggest\JsonSchema\Schema;
@@ -164,7 +165,7 @@ protected function makeOptions($version)
164165
*/
165166
protected function runSpecTest($schemaData, $data, $isValid, $name, $version)
166167
{
167-
168+
Format::$strictDateTimeValidation = true;
168169
$actualValid = true;
169170
$error = '';
170171
try {

0 commit comments

Comments
 (0)