From 48794959c409854801d7c135ac367bb7ce3ff69a Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 1 Oct 2018 22:06:05 +0100 Subject: [PATCH] Fix parsing --- blocks/ORB/Common.pm | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/blocks/ORB/Common.pm b/blocks/ORB/Common.pm index 2536302..3290b82 100644 --- a/blocks/ORB/Common.pm +++ b/blocks/ORB/Common.pm @@ -28,6 +28,7 @@ use JSON; # How many ingredient rows should appear in the empty form? use constant DEFAULT_INGREDIENT_COUNT => 5; +use Data::Dumper; # ============================================================================ # Page generation support functions @@ -266,9 +267,9 @@ sub _validate_ingredient { my $ingdata = shift; my ($error, $errors) = ("", ""); - # Do nothing unless something has been set for the quantity and name + # Do nothing unless something has been set for the name return "" - unless($ingdata -> {"quantity"} && $ingdata -> {"name"}); + unless($ingdata -> {"name"}); # Start accumulating ingredient data here my $ingredient = { @@ -277,11 +278,13 @@ sub _validate_ingredient { }; # Quantity valid? - if($ingdata -> {"quantity"} =~ /^\d+(\.\d+)?$/) { - $ingredient -> {"quantity"} = $ingdata -> {"quantity"}; - } else { - $errors .= $self -> {"template"} -> load_template("error/error_item.tem", - { "%(error)s" => "{L_ERR_BADQUANTITY}" }); + if($ingdata -> {"quantity"}) { + if($ingdata -> {"quantity"} =~ /$self->{formats}->{quantity}/) { + $ingredient -> {"quantity"} = $ingdata -> {"quantity"}; + } else { + $errors .= $self -> {"template"} -> load_template("error/error_item.tem", + { "%(error)s" => "{L_ERR_BADQUANTITY}" }); + } } # Name valid? @@ -353,6 +356,7 @@ sub _validate_ingredients { $errors .= $self -> _validate_ingredient($args, $ingred); } } + print STDERR "Out: ",Dumper($args -> {"ingredients"})."\n"; return $errors; } @@ -401,10 +405,10 @@ sub _validate_recipe { if($error); #