Don't allow implicit matching of strings against masks, =~ is needed.
This commit is contained in:
parent
cf9b4a3873
commit
46b35a015b
2 changed files with 23 additions and 11 deletions
30
src/item.cc
30
src/item.cc
|
|
@ -141,18 +141,29 @@ namespace {
|
||||||
value_t& arg(args[0]);
|
value_t& arg(args[0]);
|
||||||
|
|
||||||
if (arg.is_string()) {
|
if (arg.is_string()) {
|
||||||
if (args.size() == 1)
|
if (args.size() == 1) {
|
||||||
return item.has_tag(args[0].as_string());
|
return item.has_tag(args[0].as_string());
|
||||||
else if (optional<string> tag = item.get_tag(args[0].as_string()))
|
}
|
||||||
return args[1] == string_value(*tag);
|
else if (optional<string> tag = item.get_tag(args[0].as_string())) {
|
||||||
|
if (args[1].is_string()) {
|
||||||
|
return args[1].as_string() == *tag;
|
||||||
|
}
|
||||||
|
else if (args[1].is_mask()) {
|
||||||
|
return args[1].as_mask().match(*tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (arg.is_mask()) {
|
else if (arg.is_mask()) {
|
||||||
foreach (const item_t::string_map::value_type& data, *item.metadata) {
|
foreach (const item_t::string_map::value_type& data, *item.metadata) {
|
||||||
if (arg.as_mask().match(data.first)) {
|
if (arg.as_mask().match(data.first)) {
|
||||||
if (args.size() == 1)
|
if (args.size() == 1)
|
||||||
return true;
|
return true;
|
||||||
else if (data.second && args[1] == string_value(*data.second))
|
else if (data.second) {
|
||||||
return true;
|
if (args[1].is_string())
|
||||||
|
return args[1].as_string() == *data.second;
|
||||||
|
else if (args[1].is_mask())
|
||||||
|
return args[1].as_mask().match(*data.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -312,8 +323,13 @@ string item_context(const item_t& item)
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
|
|
||||||
out << "While balancing item from \"" << path.string()
|
out << "While balancing item from \"" << path.string()
|
||||||
<< "\", line " << item.beg_line
|
<< "\"";
|
||||||
<< ", byte " << item.beg_pos << ":\n";
|
|
||||||
|
if (item.beg_line != (item.end_line - 1))
|
||||||
|
out << ", lines " << item.beg_line << "-"
|
||||||
|
<< (item.end_line - 1) << ":\n";
|
||||||
|
else
|
||||||
|
out << ", line " << item.beg_line << ":\n";
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (char * p = std::strtok(buf.get(), "\n");
|
for (char * p = std::strtok(buf.get(), "\n");
|
||||||
|
|
|
||||||
|
|
@ -944,15 +944,11 @@ bool value_t::is_equal_to(const value_t& val) const
|
||||||
case STRING:
|
case STRING:
|
||||||
if (val.is_string())
|
if (val.is_string())
|
||||||
return as_string() == val.as_string();
|
return as_string() == val.as_string();
|
||||||
else if (val.is_mask())
|
|
||||||
return val.as_mask().match(as_string());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MASK:
|
case MASK:
|
||||||
if (val.is_mask())
|
if (val.is_mask())
|
||||||
return as_mask() == val.as_mask();
|
return as_mask() == val.as_mask();
|
||||||
else if (val.is_string())
|
|
||||||
return as_mask().match(val.as_string());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEQUENCE:
|
case SEQUENCE:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue