Skip to content

Commit 95564d8

Browse files
fix isTypeCorrect function for char and strings with fixed length (#30)
1 parent a731d0c commit 95564d8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/requestHandler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,16 +894,17 @@ class RequestChecker {
894894
* @returns {boolean} True if the value is
895895
*/
896896
isTypeCorrect (key, value, model) {
897-
const type = model[key].type // The column type
897+
const column = model[key]
898+
const type = column.type // The column type
898899
if (value === undefined || value === null) return !model[key].notNull
899900
switch (type) {
900901
case 'string':
901902
case 'varchar':
902903
case 'time':
903904
case 'text':
904-
return Object(value) instanceof String
905+
return (Object(value) instanceof String) && (column.length !== undefined ? value.length <= column.length : true)
905906
case 'char':
906-
return (Object(value) instanceof String) && value.length === 1
907+
return (Object(value) instanceof String) && (column.length !== undefined ? value.length <= column.length : true)
907908
case 'integer':
908909
case 'year':
909910
return Number.isInteger(value)

0 commit comments

Comments
 (0)