Changeset 13617 in josm for trunk


Ignore:
Timestamp:
2018-04-12T01:18:50+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #16180 - make sure changeset dialog example URLs are valid

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/UrlBasedQueryPanel.java

    r13613 r13617  
    1212import java.net.MalformedURLException;
    1313import java.net.URL;
     14import java.util.Arrays;
     15import java.util.List;
     16import java.util.stream.Collectors;
    1417
    1518import javax.swing.BorderFactory;
     
    7578    }
    7679
     80    protected static List<String> getExamples() {
     81        return Arrays.asList(
     82                Main.getOSMWebsite()+"/history?open=true",
     83                OsmApi.getOsmApi().getBaseUrl()+"/changesets?open=true");
     84    }
     85
    7786    protected JPanel buildHelpPanel() {
    7887        String apiUrl = OsmApi.getOsmApi().getBaseUrl();
     
    8392                + "<p><strong>" + tr("Examples") + "</strong></p>"
    8493                + "<ul>"
    85                 + "<li><a href=\""+Main.getOSMWebsite()+"/history?open=true\">"+Main.getOSMWebsite()+"/history?open=true</a></li>"
    86                 + "<li><a href=\""+apiUrl+"/changesets?open=true\">"+apiUrl+"/changesets?open=true</a></li>"
     94                + String.join("", getExamples().stream().map(
     95                        s -> "<li><a href=\""+s+"\">"+s+"</a></li>").collect(Collectors.toList()))
    8796                + "</ul>"
    8897                + tr("Note that changeset queries are currently always submitted to ''{0}'', regardless of the "
     
    121130    }
    122131
    123     protected boolean isValidChangesetQueryUrl(String text) {
     132    protected static boolean isValidChangesetQueryUrl(String text) {
    124133        return buildChangesetQuery(text) != null;
    125134    }
    126135
    127     protected ChangesetQuery buildChangesetQuery(String text) {
     136    protected static ChangesetQuery buildChangesetQuery(String text) {
    128137        URL url = null;
    129138        try {
     
    133142        }
    134143        String path = url.getPath();
    135         if (path == null || !path.endsWith("/changesets"))
     144        if (path == null || (!path.endsWith("/changesets") && !path.endsWith("/history")))
    136145            return null;
    137146
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/changeset/query/UrlBasedQueryPanelTest.java

    r10962 r13617  
    33
    44import static org.junit.Assert.assertNotNull;
     5import static org.junit.Assert.assertTrue;
    56
    67import org.junit.Rule;
     
    2930        assertNotNull(new UrlBasedQueryPanel());
    3031    }
     32
     33    /**
     34     * Checks that examples displayed in panel are correct.
     35     */
     36    @Test
     37    public void testExamplesAreCorrect() {
     38        for (String example : UrlBasedQueryPanel.getExamples()) {
     39            assertTrue(example, UrlBasedQueryPanel.isValidChangesetQueryUrl(example));
     40        }
     41    }
    3142}
Note: See TracChangeset for help on using the changeset viewer.