Skip to content

Commit 664dfff

Browse files
committed
handle negative integers, fixes #1
1 parent c2b9643 commit 664dfff

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

postgres-json-schema--0.1.0.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BEGIN
44
IF jsonb_typeof(data) != 'number' THEN
55
RETURN false;
66
END IF;
7-
IF NOT data::text SIMILAR TO '[0-9]+' THEN
7+
IF trunc(data::text::numeric) != data::text::numeric THEN
88
RETURN false;
99
END IF;
1010
ELSE

tests.sql

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ BEGIN
77
ASSERT validate_json_schema('{"type": "number"}', '123');
88
ASSERT validate_json_schema('{"type": "integer"}', '123');
99
ASSERT NOT validate_json_schema('{"type": "integer"}', '123.1');
10+
ASSERT validate_json_schema('{"type": "integer"}', '-103948');
1011
ASSERT NOT validate_json_schema('{"type": "number"}', '"a"');
1112
ASSERT validate_json_schema('{"type": "string"}', '"a"');
1213
ASSERT NOT validate_json_schema('{"type": "string"}', '{}');
@@ -55,6 +56,7 @@ BEGIN
5556
ASSERT validate_json_schema('{"enum": [1,2,3]}', '1');
5657
ASSERT NOT validate_json_schema('{"enum": [1,2,3]}', '4');
5758

59+
5860
RETURN true;
5961
END;
6062
$f$ LANGUAGE 'plpgsql';

0 commit comments

Comments
 (0)