util.dataforms: Fix interaction of required fields and empty string values (fixes...
authorKim Alvefur <zash@zash.se>
Sat, 12 Sep 2015 15:49:47 +0000 (17:49 +0200)
committerKim Alvefur <zash@zash.se>
Sat, 12 Sep 2015 15:49:47 +0000 (17:49 +0200)
util/dataforms.lua

index 30b5344a7bbc4d3b227d52f5e3d2684f36318225..05846ab3a5b58614df89ba1c779ecc848d096b36 100644 (file)
@@ -147,11 +147,12 @@ end
 
 local function simple_text(field_tag, required)
        local data = field_tag:get_child_text("value");
-       if data and #data > 0 then
-               return data
-       elseif required then
+       -- XEP-0004 does not say if an empty string is acceptable for a required value
+       -- so we will follow HTML5 which says that empty string means missing
+       if required and (data == nil or data == "") then
                return nil, "Required value missing";
        end
+       return data; -- Return whatever get_child_text returned, even if empty string
 end
 
 field_readers["text-single"] = simple_text;