Skip to content

Commit 4742c46

Browse files
Stricter type checks for boolean
1 parent c6b3542 commit 4742c46

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

include/rfl/xml/Reader.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ struct Reader {
8585
return std::visit(get_value, _var.node_or_attribute_);
8686

8787
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
88-
return std::visit(get_value, _var.node_or_attribute_) == "true";
88+
const auto val = std::visit(get_value, _var.node_or_attribute_);
89+
if (val == "true" || val == "1") {
90+
return true;
91+
} else if (val == "false" || val == "0") {
92+
return false;
93+
} else {
94+
return error("Could not cast '" + val + "' to boolean.");
95+
}
8996

9097
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
9198
const auto str = std::visit(get_value, _var.node_or_attribute_);

0 commit comments

Comments
 (0)