Patchwork [bitbake-devel,42/94] bitbake: webhob: improve validation code flow

login
register
mail settings
Submitter Alexandru DAMIAN
Date Sept. 24, 2013, 4:52 p.m.
Message ID <f05a50553c182f3a688d0ed53beefac25932f61e.1380041477.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/58739/
State New
Headers show

Comments

Alexandru DAMIAN - Sept. 24, 2013, 4:52 p.m.
From: Calin Dragomir <calinx.l.dragomir@intel.com>

This patch improves the code flow in the validation method
by not repeating the split method over the same list and
by stoping at any invalid input encountered.

Signed-off-by: Calin Dragomir <calinx.l.dragomir@intel.com>
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 bitbake/lib/webhob/bldviewer/views.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch

diff --git a/bitbake/lib/webhob/bldviewer/views.py b/bitbake/lib/webhob/bldviewer/views.py
index 73f7ba7..647a1f2 100644
--- a/bitbake/lib/webhob/bldviewer/views.py
+++ b/bitbake/lib/webhob/bldviewer/views.py
@@ -139,17 +139,20 @@  def _validate_input(input, model):
         input_list = input.split(":")
 
         # Check we have only one colon
-        if len(input.split(":")) != 2:
+        if len(input_list) != 2:
             invalid = 1
+            return None, invalid
 
         # Check we have an equal number of terms both sides of the colon
         if len(input_list[0].split(',')) != len(input_list[1].split(',')):
             invalid = 1
+            return None, invalid
 
         # Check we are looking for a valid field
         valid_fields = model._meta.get_all_field_names()
         for field in input_list[0].split(','):
             if field not in valid_fields:
                 invalid = 1
+                return None, invalid
 
     return input, invalid