Maurits van der Schee 4 years ago
parent
commit
a7f1fb7aa3

+ 2
- 2
api.php View File

@@ -8433,9 +8433,9 @@ namespace Tqdev\PhpCrudApi\Middleware {
8433 8433
     						break;
8434 8434
     					case 'decimal':
8435 8435
     						if (strpos($value, '.') !== false) {
8436
-    							list($whole, $decimals) = explode('.', $value, 2);
8436
+    							list($whole, $decimals) = explode('.', ltrim($value, '-'), 2);
8437 8437
     						} else {
8438
-    							list($whole, $decimals) = array($value, '');
8438
+    							list($whole, $decimals) = array(ltrim($value, '-'), '');
8439 8439
     						}
8440 8440
     						if (strlen($whole) > 0 && !ctype_digit($whole)) {
8441 8441
     							return 'invalid decimal';

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/ValidationMiddleware.php View File

@@ -83,9 +83,9 @@ class ValidationMiddleware extends Middleware
83 83
 						break;
84 84
 					case 'decimal':
85 85
 						if (strpos($value, '.') !== false) {
86
-							list($whole, $decimals) = explode('.', $value, 2);
86
+							list($whole, $decimals) = explode('.', ltrim($value, '-'), 2);
87 87
 						} else {
88
-							list($whole, $decimals) = array($value, '');
88
+							list($whole, $decimals) = array(ltrim($value, '-'), '');
89 89
 						}
90 90
 						if (strlen($whole) > 0 && !ctype_digit($whole)) {
91 91
 							return 'invalid decimal';

+ 20
- 0
tests/functional/003_columns/015_update_types_table.log View File

@@ -112,6 +112,26 @@ Content-Length: 101
112 112
 ===
113 113
 PUT /records/types/1
114 114
 
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
+
115 135
 {"decimal":"12.23.34"}
116 136
 ===
117 137
 422

Loading…
Cancel
Save