From 13be09eaa80370d9af7bf2c599c0d83f81a62d93 Mon Sep 17 00:00:00 2001
From: Florian Kargl <f.kargl@posteo.de>
Date: Fri, 22 Oct 2021 13:43:01 +0200
Subject: [PATCH] Fix parsing of empty parenthesis pairs in search expressions
---
.../josm/data/osm/search/SearchCompiler.java | 2 +-
.../josm/data/osm/search/SearchCompilerTest.java | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java b/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
index d299110d8b..0e6612d0d7 100644
a
|
b
|
private Match parseFactor() throws SearchParseError {
|
2128 | 2128 | Match expression = parseExpression(); |
2129 | 2129 | if (!tokenizer.readIfEqual(Token.RIGHT_PARENT)) |
2130 | 2130 | throw new SearchParseError(Token.RIGHT_PARENT, tokenizer.nextToken()); |
2131 | | return expression; |
| 2131 | return expression != null ? expression : Always.INSTANCE; |
2132 | 2132 | } else if (tokenizer.readIfEqual(Token.NOT)) { |
2133 | 2133 | return new Not(parseFactor(tr("Missing operator for NOT"))); |
2134 | 2134 | } else if (tokenizer.readIfEqual(Token.KEY)) { |
diff --git a/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java b/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
index d8d5b88dac..87ca23343e 100644
a
|
b
|
void testRole() throws SearchParseError {
|
840 | 840 | void testNonRegression21300(final String searchString) { |
841 | 841 | assertThrows(SearchParseError.class, () -> SearchCompiler.compile(searchString)); |
842 | 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Non-regression test for JOSM #21463 |
| 846 | */ |
| 847 | @Test |
| 848 | void testNonRegression21463() throws SearchParseError { |
| 849 | final SearchCompiler.Match c = SearchCompiler.compile("foo () () () bar"); |
| 850 | assertTrue(c.match(OsmUtils.createPrimitive("node foo=bar"))); |
| 851 | assertFalse(c.match(OsmUtils.createPrimitive("node name=bar"))); |
| 852 | } |
843 | 853 | } |