Changeset 13335 in josm


Ignore:
Timestamp:
2018-01-19T20:15:02+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #15800 - autofix common issues in overpass queries, like overpass turbo

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

    r13130 r13335  
    192192            };
    193193
    194             return new OverpassDownloadData(query, errorReporter);
     194            return new OverpassDownloadData(OverpassDownloadReader.fixQuery(query), errorReporter);
    195195        }
    196196
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r12841 r13335  
    394394        return ds;
    395395    }
     396
     397    /**
     398     * Fixes Overpass API query to make sure it will be accepted by JOSM.
     399     * @param query Overpass query to check
     400     * @return fixed query
     401     * @since 13335
     402     */
     403    public static String fixQuery(String query) {
     404        return query.replaceFirst("out( body| skel| ids)?( id| qt)?;", "out meta$2;");
     405    }
    396406}
  • trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java

    r12714 r13335  
    175175                "out meta;").matches());
    176176    }
     177
     178    /**
     179     * Test {@link OverpassDownloadReader#fixQuery(String)}.
     180     */
     181    @Test
     182    public void testFixQuery() {
     183        assertEquals("out meta;", OverpassDownloadReader.fixQuery("out;"));
     184        assertEquals("out meta;", OverpassDownloadReader.fixQuery("out body;"));
     185        assertEquals("out meta;", OverpassDownloadReader.fixQuery("out skel;"));
     186        assertEquals("out meta;", OverpassDownloadReader.fixQuery("out ids;"));
     187
     188        assertEquals("out meta id;", OverpassDownloadReader.fixQuery("out id;"));
     189        assertEquals("out meta id;", OverpassDownloadReader.fixQuery("out body id;"));
     190        assertEquals("out meta id;", OverpassDownloadReader.fixQuery("out skel id;"));
     191        assertEquals("out meta id;", OverpassDownloadReader.fixQuery("out ids id;"));
     192
     193        assertEquals("out meta qt;", OverpassDownloadReader.fixQuery("out qt;"));
     194        assertEquals("out meta qt;", OverpassDownloadReader.fixQuery("out body qt;"));
     195        assertEquals("out meta qt;", OverpassDownloadReader.fixQuery("out skel qt;"));
     196        assertEquals("out meta qt;", OverpassDownloadReader.fixQuery("out ids qt;"));
     197
     198        assertEquals("[timeout:25];\n" +
     199                "(\n" +
     200                "  node[\"historic\"=\"ringfort\"];\n" +
     201                "  way[\"historic\"=\"ringfort\"];\n" +
     202                ");\n" +
     203                "out meta;",
     204            OverpassDownloadReader.fixQuery("[timeout:25];\n" +
     205                "(\n" +
     206                "  node[\"historic\"=\"ringfort\"];\n" +
     207                "  way[\"historic\"=\"ringfort\"];\n" +
     208                ");\n" +
     209                "out body;"));
     210    }
    177211}
Note: See TracChangeset for help on using the changeset viewer.