Changeset 13336 in josm


Ignore:
Timestamp:
2018-01-19T20:42:21+01:00 (4 months ago)
Author:
Don-vip
Message:

see #15800 - autofix out: issues in overpass queries

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r13335 r13336  
    402402     */
    403403    public static String fixQuery(String query) {
    404         return query.replaceFirst("out( body| skel| ids)?( id| qt)?;", "out meta$2;");
     404        return query == null ? query : query
     405                .replaceFirst("out( body| skel| ids)?( id| qt)?;", "out meta$2;")
     406                .replaceFirst("(?s)\\[out:(json|csv)[^\\]]*\\]", "[out:xml]");
    405407    }
    406408}
  • trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java

    r13335 r13336  
    88import static org.junit.Assert.assertEquals;
    99import static org.junit.Assert.assertNotNull;
     10import static org.junit.Assert.assertNull;
    1011import static org.junit.Assert.assertTrue;
    1112
     
    181182    @Test
    182183    public void testFixQuery() {
     184        assertNull(OverpassDownloadReader.fixQuery(null));
     185
    183186        assertEquals("out meta;", OverpassDownloadReader.fixQuery("out;"));
    184187        assertEquals("out meta;", OverpassDownloadReader.fixQuery("out body;"));
     
    196199        assertEquals("out meta qt;", OverpassDownloadReader.fixQuery("out ids qt;"));
    197200
    198         assertEquals("[timeout:25];\n" +
     201        assertEquals("[out:xml]", OverpassDownloadReader.fixQuery("[out:json]"));
     202        assertEquals("[out:xml]", OverpassDownloadReader.fixQuery("[out:csv(\n" +
     203                "    ::\"id\", amenity, name, operator, opening_hours, \"contact:website\", \"contact:phone\", brand, dispensing, lastcheck\n" +
     204                "  )]"));
     205
     206        assertEquals("[out:xml][timeout:25];\n" +
    199207                "(\n" +
    200208                "  node[\"historic\"=\"ringfort\"];\n" +
     
    202210                ");\n" +
    203211                "out meta;",
    204             OverpassDownloadReader.fixQuery("[timeout:25];\n" +
     212            OverpassDownloadReader.fixQuery("[out:xml][timeout:25];\n" +
    205213                "(\n" +
    206214                "  node[\"historic\"=\"ringfort\"];\n" +
Note: See TracChangeset for help on using the changeset viewer.