Fixes #3361 - Check for null and undefined values in validateParam
This commit is contained in:
@@ -485,6 +485,10 @@ export const validateParam = (param, isXml) => {
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( value === null || value === undefined ) {
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
if ( type === "number" ) {
|
if ( type === "number" ) {
|
||||||
let err = validateNumber(value)
|
let err = validateNumber(value)
|
||||||
if (!err) return errors
|
if (!err) return errors
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ describe("utils", function(){
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("validates numbers", function() {
|
it("validates numbers", function() {
|
||||||
|
// string instead of a number
|
||||||
param = fromJS({
|
param = fromJS({
|
||||||
required: false,
|
required: false,
|
||||||
type: "number",
|
type: "number",
|
||||||
@@ -221,9 +222,28 @@ describe("utils", function(){
|
|||||||
})
|
})
|
||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( ["Value must be a number"] )
|
expect( result ).toEqual( ["Value must be a number"] )
|
||||||
|
|
||||||
|
// undefined value
|
||||||
|
param = fromJS({
|
||||||
|
required: false,
|
||||||
|
type: "number",
|
||||||
|
value: undefined
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( [] )
|
||||||
|
|
||||||
|
// null value
|
||||||
|
param = fromJS({
|
||||||
|
required: false,
|
||||||
|
type: "number",
|
||||||
|
value: null
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( [] )
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates integers", function() {
|
it("validates integers", function() {
|
||||||
|
// string instead of integer
|
||||||
param = fromJS({
|
param = fromJS({
|
||||||
required: false,
|
required: false,
|
||||||
type: "integer",
|
type: "integer",
|
||||||
@@ -231,6 +251,24 @@ describe("utils", function(){
|
|||||||
})
|
})
|
||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( ["Value must be an integer"] )
|
expect( result ).toEqual( ["Value must be an integer"] )
|
||||||
|
|
||||||
|
// undefined value
|
||||||
|
param = fromJS({
|
||||||
|
required: false,
|
||||||
|
type: "integer",
|
||||||
|
value: undefined
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( [] )
|
||||||
|
|
||||||
|
// null value
|
||||||
|
param = fromJS({
|
||||||
|
required: false,
|
||||||
|
type: "integer",
|
||||||
|
value: null
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( [] )
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates arrays", function() {
|
it("validates arrays", function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user