Index: /trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java	(revision 6154)
+++ /trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java	(revision 6155)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.tools;
 
+import java.awt.HeadlessException;
 import java.awt.Toolkit;
 import java.io.UnsupportedEncodingException;
@@ -27,11 +28,12 @@
         if (b != null)
             return b;
-        int i = url.indexOf('?');
+        int i = url.indexOf("#map");
+        if (i >= 0) {
+            // probably it's a URL following the new scheme?
+            return parseHashURLs(url);
+        }
+        i = url.indexOf('?');
         if (i == -1) {
-            //probably it's a URL following the new scheme?
-            if (url.indexOf('#') >= 0)
-                return parseHashURLs(url);
-            else
-                return null;
+            return null;
         }
         String[] args = url.substring(i+1).split("&");
@@ -80,15 +82,15 @@
      * The following function, called by the old parse function if necessary, provides parsing new URLs
      * the new URLs follow the scheme http://www.openstreetmap.org/#map=18/51.71873/8.76164&layers=CN
-     * @param url
-     * @return
+     * @param url string for parsing
+     * @return Bounds if hashurl, {@code null} otherwise
      */
     private static Bounds parseHashURLs(String url) {
-        int startIndex = url.indexOf("=");
+        int startIndex = url.indexOf("#map=");
         if (startIndex == -1) return null;
-        int endIndex = url.indexOf("&");
+        int endIndex = url.indexOf('&', startIndex);
         if (endIndex == -1) endIndex = url.length();
         try
         {
-            String coordPart = url.substring(startIndex+1, endIndex);
+            String coordPart = url.substring(startIndex+5, endIndex);
             String[] parts = coordPart.split("/");
             Bounds b = positionToBounds(Double.parseDouble(parts[1]),
@@ -181,9 +183,17 @@
     public static Bounds positionToBounds(final double lat, final double lon, final int zoom) {
         int tileSizeInPixels = 256;
-        int height = Toolkit.getDefaultToolkit().getScreenSize().height;
-        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
-        if (Main.isDisplayingMapView()) {
-            height = Main.map.mapView.getHeight();
-            width = Main.map.mapView.getWidth();
+        int height;
+        int width;
+        try {
+            height = Toolkit.getDefaultToolkit().getScreenSize().height;
+            width = Toolkit.getDefaultToolkit().getScreenSize().width;
+            if (Main.isDisplayingMapView()) {
+                height = Main.map.mapView.getHeight();
+                width = Main.map.mapView.getWidth();
+            }
+        } catch (HeadlessException he) {
+            // in headless mode, when running tests
+            height = 480;
+            width = 640;
         }
         double scale = (1 << zoom) * tileSizeInPixels / (2 * Math.PI * R);
Index: /trunk/test/unit/org/openstreetmap/josm/tools/OsmUrlToBoundsTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/tools/OsmUrlToBoundsTest.java	(revision 6155)
+++ /trunk/test/unit/org/openstreetmap/josm/tools/OsmUrlToBoundsTest.java	(revision 6155)
@@ -0,0 +1,58 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.tools;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openstreetmap.josm.data.Bounds;
+
+/**
+  * Unit tests of {@link OsmUrlToBounds} class.
+*/
+public class OsmUrlToBoundsTest {
+    /**
+     * data for {@link #testParse}
+     */
+    private static final ParseTestItem[] parseTestData = {
+        new ParseTestItem("http://www.openstreetmap.org", null),
+        new ParseTestItem("http://www.openstreetmap.org/?bbox=-0.489,51.28,0.236,51.686", new Bounds(51.28, -0.489, 51.686, 0.236)),
+        new ParseTestItem("http://www.openstreetmap.org/?minlon=-0.489&minlat=51.28&maxlon=0.236&maxlat=51.686", new Bounds(51.28, -0.489, 51.686, 0.236)),
+        new ParseTestItem("http://www.openstreetmap.org/?maxlat=51.686&maxlon=0.236&minlat=51.28&minlon=-0.489", new Bounds(51.28, -0.489, 51.686, 0.236)),
+        new ParseTestItem("http://www.openstreetmap.org/?zoom=17&lat=51.71873&lon=8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
+        new ParseTestItem("http://www.openstreetmap.org/?lon=8.76164&lat=51.71873&zoom=17&foo", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
+        new ParseTestItem("http://www.openstreetmap.org/?mlon=8.76164&mlat=51.71873", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 18)),
+        new ParseTestItem("http://osm.org/go/euulwp", OsmUrlToBounds.positionToBounds(51.48262023925781, -0.29937744140625, 8)),
+        new ParseTestItem("http://www.openstreetmap.org/#map=17/51.71873/8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
+        new ParseTestItem("http://www.openstreetmap.org/#map=17/51.71873/8.76164&layers=CN", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
+        new ParseTestItem("http%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
+        new ParseTestItem("http%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164%26layers%3DCN", OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
+        new ParseTestItem("http://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020", OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
+        new ParseTestItem("http://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020&layers=N", OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
+        new ParseTestItem("http://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.1270", OsmUrlToBounds.positionToBounds(51.4831, -0.1270, 10)),
+        new ParseTestItem("http://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.3509&layers=T", OsmUrlToBounds.positionToBounds(51.4831, -0.3509, 10)),
+        new ParseTestItem("http://www.openstreetmap.org/#map", null),
+        new ParseTestItem("http://www.openstreetmap.org/#map=foo", null),
+        new ParseTestItem("http://www.openstreetmap.org/#map=fooz/foolat/foolon", null)
+    };
+
+    private static class ParseTestItem {
+        public String url;
+        public Bounds bounds;
+        
+        public ParseTestItem(String url, Bounds bounds) {
+            this.url = url;
+            this.bounds = bounds;
+        }
+    }
+
+    /**
+     * Test URL parsing
+     */
+    @Test
+    public void testParse() {
+        for (ParseTestItem item : parseTestData) {
+            Bounds bounds = OsmUrlToBounds.parse(item.url);
+            Assert.assertEquals(item.url, item.bounds, bounds);
+        }
+    }
+
+}
