Ticket #21463: josm_search_parens_fix.patch

File josm_search_parens_fix.patch, 2.2 KB (added by Woazboat, 3 years ago)

Simple patch that should fix this issue by returning the Always matcher instead of null for empty parentheses

  • src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    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 {  
    21282128            Match expression = parseExpression();
    21292129            if (!tokenizer.readIfEqual(Token.RIGHT_PARENT))
    21302130                throw new SearchParseError(Token.RIGHT_PARENT, tokenizer.nextToken());
    2131             return expression;
     2131            return expression != null ? expression : Always.INSTANCE;
    21322132        } else if (tokenizer.readIfEqual(Token.NOT)) {
    21332133            return new Not(parseFactor(tr("Missing operator for NOT")));
    21342134        } else if (tokenizer.readIfEqual(Token.KEY)) {
  • test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    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 {  
    840840    void testNonRegression21300(final String searchString) {
    841841        assertThrows(SearchParseError.class, () -> SearchCompiler.compile(searchString));
    842842    }
     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    }
    843853}