Commit ff6faf40 authored by Volker Krause's avatar Volker Krause
Browse files

Extend input data violation to non-scalar data

parent 5ee2394f
......@@ -126,26 +126,8 @@ class Sample
continue;
$v = $jsonObj->{$entry->name}->{$elem->name};
switch ($entry->type) {
case SchemaEntryElement::STRING_TYPE:
if (!is_string($v))
continue;
break;
case SchemaEntryElement::INT_TYPE:
if (!is_int($v))
continue;
break;
case SchemaEntryElement::NUMBER_TYPE:
if (!is_float($v))
continue;
break;
case SchemaEntryElement::BOOL_TYPE:
if (!is_bool($v))
continue;
break;
default:
continue;
}
if (!self::isCorrectType($elem, $v))
continue;
$bind = ':' . $elem->dataColumnName();
array_push($columns, $elem->dataColumnName());
......@@ -214,8 +196,10 @@ class Sample
$bindValues[':' . $elem->dataColumnName()] = null;
if (!property_exists($entry, $elem->name))
continue;
// TODO type check, as done for scalar values
$bindValues[':' . $elem->dataColumnName()] = $entry->{$elem->name};
$v = $entry->{$elem->name};
if (!self::isCorrectType($elem, $v))
continue;
$bindValues[':' . $elem->dataColumnName()] = $v;
}
$db->execute($stmt, $bindValues);
}
......@@ -238,6 +222,30 @@ class Sample
}
Utils::httpError(500, "Invalid schema entry element type.");
}
/** Check if the given input value @p $v matches the expected type for element @p $elem. */
private static function isCorrectType(SchemaEntryElement $elem, $v)
{
switch ($elem->type) {
case SchemaEntryElement::STRING_TYPE:
if (!is_string($v))
return false;
break;
case SchemaEntryElement::INT_TYPE:
if (!is_int($v))
return false;
break;
case SchemaEntryElement::NUMBER_TYPE:
if (!is_float($v))
return false;
break;
case SchemaEntryElement::BOOL_TYPE:
if (!is_bool($v))
return false;
break;
}
return true;
}
}
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment