Software / code / prosody
Comparison
util/dataforms.lua @ 6830:e08f5d081a6c
util.dataforms: Fix interaction of required fields and empty string values (fixes #521)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 12 Sep 2015 17:49:47 +0200 |
| parent | 6829:22522443982f |
| child | 6981:bcaa553de6e8 |
comparison
equal
deleted
inserted
replaced
| 6829:22522443982f | 6830:e08f5d081a6c |
|---|---|
| 145 return data; | 145 return data; |
| 146 end | 146 end |
| 147 | 147 |
| 148 local function simple_text(field_tag, required) | 148 local function simple_text(field_tag, required) |
| 149 local data = field_tag:get_child_text("value"); | 149 local data = field_tag:get_child_text("value"); |
| 150 if data and #data > 0 then | 150 -- XEP-0004 does not say if an empty string is acceptable for a required value |
| 151 return data | 151 -- so we will follow HTML5 which says that empty string means missing |
| 152 elseif required then | 152 if required and (data == nil or data == "") then |
| 153 return nil, "Required value missing"; | 153 return nil, "Required value missing"; |
| 154 end | 154 end |
| 155 return data; -- Return whatever get_child_text returned, even if empty string | |
| 155 end | 156 end |
| 156 | 157 |
| 157 field_readers["text-single"] = simple_text; | 158 field_readers["text-single"] = simple_text; |
| 158 | 159 |
| 159 field_readers["text-private"] = simple_text; | 160 field_readers["text-private"] = simple_text; |