Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Accept 0 and 1 for boolean values
......................................................................

restapi: Accept 0 and 1 for boolean values

According to section section 3.2.2.1 of the XML specification the values
0 and 1 should be accepted for boolean values in addition to "false" and
"true":

  3.2.2 boolean, 3.2.2.1 Lexical representation
  http://www.w3.org/TR/xmlschema-2/#boolean

In a previous change intended to validate the values of booleans the
RESTAPI was changed to accept only "false" and "true":

  restapi: Validate boolean values
  https://gerrit.ovirt.org/27925

This causes a regression for users that are sending 0 and 1. This patch
fixes that so that 0 and 1 will also be accepted.

Change-Id: I4a5005fdafa1e45e5ad17178a5ac897e6234f45b
Bug-Url: https://bugzilla.redhat.com/1230842
Related: https://bugzilla.redhat.com/1063876
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/BooleanParser.java
1 file changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/42232/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/BooleanParser.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/BooleanParser.java
index f96b1af..6626437 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/BooleanParser.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/BooleanParser.java
@@ -1,18 +1,20 @@
 package org.ovirt.engine.api.utils;
 
 /**
- * This class contains methods that parse boolean from strings accepting only 
the values {@code true} and {@code false}.
+ * This class contains methods that parse boolean from strings accepting only 
the values {@code true}, {@code false},
+ * {@code 0} and {@code 1} as described in <a 
href="http://www.w3.org/TR/xmlschema-2/#boolean";>section 3.2.2.1</a> of
+ * the XML schema specification {@link}
  */
 public class BooleanParser {
     public static boolean parseBoolean(String value) {
-        if ("true".equalsIgnoreCase(value)) {
+        if ("true".equalsIgnoreCase(value) || "1".equals(value)) {
             return true;
         }
-        if ("false".equalsIgnoreCase(value)) {
+        if ("false".equalsIgnoreCase(value) || "0".equals(value)) {
             return false;
         }
         throw new InvalidValueException(
-            "Value \"" + value + "\" isn't a valid boolean, it should be 
\"true\" or \"false\""
+            "Value \"" + value + "\" isn't a valid boolean, it should be 
\"true\" , \"false\", \"0\" or \"1\""
         );
     }
 }


-- 
To view, visit https://gerrit.ovirt.org/42232
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a5005fdafa1e45e5ad17178a5ac897e6234f45b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to