Commit 79a9701f63b8cef7e227cef96fd24ef834ce3045
1 parent
3d29a053
Refactor `QPDFFormFieldObjectHelper`: streamline checkbox and radio button value…
… validation, improve readability, and reduce redundancy in type checks.
Showing
1 changed file
with
15 additions
and
14 deletions
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -304,25 +304,26 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) | @@ -304,25 +304,26 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) | ||
| 304 | { | 304 | { |
| 305 | if (getFieldType() == "/Btn") { | 305 | if (getFieldType() == "/Btn") { |
| 306 | if (isCheckbox()) { | 306 | if (isCheckbox()) { |
| 307 | - bool okay = false; | ||
| 308 | - if (value.isName()) { | ||
| 309 | - std::string name = value.getName(); | ||
| 310 | - okay = true; | ||
| 311 | - // Accept any value other than /Off to mean checked. Files have been seen that use | ||
| 312 | - // /1 or other values. | ||
| 313 | - setCheckBoxValue((name != "/Off")); | ||
| 314 | - } | ||
| 315 | - if (!okay) { | 307 | + if (!value.isName()) { |
| 316 | warn("ignoring attempt to set a checkbox field to a value whose type is not name"); | 308 | warn("ignoring attempt to set a checkbox field to a value whose type is not name"); |
| 309 | + return; | ||
| 317 | } | 310 | } |
| 318 | - } else if (isRadioButton()) { | ||
| 319 | - if (value.isName()) { | ||
| 320 | - setRadioButtonValue(value); | ||
| 321 | - } else { | 311 | + std::string name = value.getName(); |
| 312 | + // Accept any value other than /Off to mean checked. Files have been seen that use | ||
| 313 | + // /1 or other values. | ||
| 314 | + setCheckBoxValue(name != "/Off"); | ||
| 315 | + return; | ||
| 316 | + } | ||
| 317 | + if (isRadioButton()) { | ||
| 318 | + if (!value.isName()) { | ||
| 322 | warn( | 319 | warn( |
| 323 | "ignoring attempt to set a radio button field to an object that is not a name"); | 320 | "ignoring attempt to set a radio button field to an object that is not a name"); |
| 321 | + return; | ||
| 324 | } | 322 | } |
| 325 | - } else if (isPushbutton()) { | 323 | + setRadioButtonValue(value); |
| 324 | + return; | ||
| 325 | + } | ||
| 326 | + if (isPushbutton()) { | ||
| 326 | warn("ignoring attempt set the value of a pushbutton field"); | 327 | warn("ignoring attempt set the value of a pushbutton field"); |
| 327 | } | 328 | } |
| 328 | return; | 329 | return; |