Skip to content

Commit a7f1fb7

Browse files
committed
Fix for #692
1 parent 696e3b9 commit a7f1fb7

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

api.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8433,9 +8433,9 @@ private function validateType(ReflectedTable $table, ReflectedColumn $column, $v
84338433
break;
84348434
case 'decimal':
84358435
if (strpos($value, '.') !== false) {
8436-
list($whole, $decimals) = explode('.', $value, 2);
8436+
list($whole, $decimals) = explode('.', ltrim($value, '-'), 2);
84378437
} else {
8438-
list($whole, $decimals) = array($value, '');
8438+
list($whole, $decimals) = array(ltrim($value, '-'), '');
84398439
}
84408440
if (strlen($whole) > 0 && !ctype_digit($whole)) {
84418441
return 'invalid decimal';

src/Tqdev/PhpCrudApi/Middleware/ValidationMiddleware.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ private function validateType(ReflectedTable $table, ReflectedColumn $column, $v
8383
break;
8484
case 'decimal':
8585
if (strpos($value, '.') !== false) {
86-
list($whole, $decimals) = explode('.', $value, 2);
86+
list($whole, $decimals) = explode('.', ltrim($value, '-'), 2);
8787
} else {
88-
list($whole, $decimals) = array($value, '');
88+
list($whole, $decimals) = array(ltrim($value, '-'), '');
8989
}
9090
if (strlen($whole) > 0 && !ctype_digit($whole)) {
9191
return 'invalid decimal';

tests/functional/003_columns/015_update_types_table.log

+20
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ Content-Length: 101
112112
===
113113
PUT /records/types/1
114114

115+
{"decimal":"-1.23"}
116+
===
117+
200
118+
Content-Type: application/json; charset=utf-8
119+
Content-Length: 1
120+
121+
1
122+
===
123+
PUT /records/types/1
124+
125+
{"decimal":"1.23"}
126+
===
127+
200
128+
Content-Type: application/json; charset=utf-8
129+
Content-Length: 1
130+
131+
1
132+
===
133+
PUT /records/types/1
134+
115135
{"decimal":"12.23.34"}
116136
===
117137
422

0 commit comments

Comments
 (0)