Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when all None in any #1932

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mapcss/mapcss_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,12 @@ def count(lst):
#any(obj1, obj2, ...)
# returns the first object which is not null (formerly coalesce, [since 7164])
def any_(*args):
if args is not None:
return next(item for item in args if item is not None and (not isinstance(item, str_value_) or not item.none))
try:
if args is not None:
return next(item for item in args if item is not None and (not isinstance(item, str_value_) or not item.none))
except StopIteration:
# All arguments are None
return None_value

#concat(str1, str2, ...)
# assemble the strings to one
Expand Down
17 changes: 17 additions & 0 deletions plugins/tests/test_mapcss_parsing_evalutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,20 @@ def node(self, data, tags):
# assertNoMatch:"node y=world"
err.append({'class': 11, 'subclass': 1778220616, 'text': mapcss.tr('test any {0} {1}', mapcss.any_(mapcss.tag(tags, 'b'), ''), mapcss.any_(mapcss.tag(tags, 'c'), mapcss.tag(tags, 'd'), ''))})

# node[any(tag("x"),tag("y"))]
if True:
match = False
if not match:
capture_tags = {}
try: match = ((mapcss.any_(mapcss.tag(tags, 'x'), mapcss.tag(tags, 'y'))))
except mapcss.RuleAbort: pass
if match:
# throwWarning:"test"
# assertMatch:"node x=yes"
# assertMatch:"node y=yes"
# assertNoMatch:"node z=yes"
err.append({'class': 6, 'subclass': 519126950, 'text': {'en': 'test'}})

return err

def way(self, data, tags, nds):
Expand Down Expand Up @@ -1099,6 +1113,9 @@ class father:
self.check_not_err(n.node(data, {'x': 'hello', 'y': 'world'}), expected={'class': 11, 'subclass': 1778220616})
self.check_err(n.node(data, {'x': 'hello'}), expected={'class': 11, 'subclass': 1778220616})
self.check_not_err(n.node(data, {'y': 'world'}), expected={'class': 11, 'subclass': 1778220616})
self.check_err(n.node(data, {'x': 'yes'}), expected={'class': 6, 'subclass': 519126950})
self.check_err(n.node(data, {'y': 'yes'}), expected={'class': 6, 'subclass': 519126950})
self.check_not_err(n.node(data, {'z': 'yes'}), expected={'class': 6, 'subclass': 519126950})
self.check_err(n.way(data, {'x': 'C00;C1;C22'}, [0]), expected={'class': 12, 'subclass': 1785050832})
self.check_err(n.way(data, {'x': 'C1'}, [0]), expected={'class': 12, 'subclass': 1785050832})
self.check_not_err(n.way(data, {'x': 'C12'}, [0]), expected={'class': 12, 'subclass': 1785050832})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,10 @@ node[a] {
assertNoMatch: "node y=world";
assertNoMatch: "node unknownkey=yes";
}

node[any(tag("x"), tag("y"))] {
throwWarning: "test";
assertMatch: "node x=yes";
assertMatch: "node y=yes";
assertNoMatch: "node z=yes";
}