]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
Details page: Allow searching for negative OSM ids
authormarc tobias <mtmail@gmx.net>
Tue, 29 Aug 2023 20:48:12 +0000 (22:48 +0200)
committermtmail <mtmail@gmx.net>
Tue, 29 Aug 2023 21:44:23 +0000 (23:44 +0200)
src/components/SearchSectionDetails.svelte
src/lib/helpers.js
test/unit/helpers.js

index f23a24c06bb4cc75905bce366428a42ed19eb183..5ca614a276da6f99b88f4b7dd8ef2522ecc5d50d 100644 (file)
@@ -6,8 +6,8 @@
   function handleFormSubmit(event) {
     let form_el = event.target;
     let val = form_el.querySelector('input[type=edit]').value.trim();
-    let type_and_id_match = val.match(/^\s*([NWR])(\d+)\s*$/i)
-                            || val.match(/\/(relation|way|node)\/(\d+)\s*$/);
+    let type_and_id_match = val.match(/^\s*([NWR])(-?\d+)\s*$/i)
+                            || val.match(/\/(relation|way|node)\/(-?\d+)\s*$/);
 
     var params = new URLSearchParams();
     if (type_and_id_match) {
@@ -30,7 +30,7 @@
       <!-- eslint-disable-next-line max-len -->
       <input type="edit"
              class="form-control form-control-sm me-1"
-             pattern="^[NWRnwr]?[0-9]+$|.*openstreetmap.*"
+             pattern="^[1-9][0-9]*$|^[NWRnwr]-?[1-9][0-9]*$|.*openstreetmap.*"
              value="{
               (api_request_params.osmtype || '')
               + (api_request_params.osmid || '')
index c95dbe9df6e0816b8f53eefd794800b3f009449d..0099d83779e04623607dc1f10a1ff305c7dac234 100644 (file)
@@ -17,7 +17,7 @@ export function formatOSMType(sType, bExcludeExternal) {
 // w123 => ['W', 123]
 export function identifyLinkInQuery(query) {
   if (!query) return undefined;
-  const m = query.match(/\/(relation|way|node)\/(\d+)/) || query.match(/^([nwr])(\d+)$/i);
+  const m = query.match(/\/(relation|way|node)\/(-?\d+)/) || query.match(/^([nwr])(-?\d+)$/i);
   if (!m) return undefined;
   return [m[1][0].toUpperCase(), Number(m[2])];
 }
index ed57c03c95f862c1c68050533f49260c6184fbee..103f2212ea77baafd9ec2fd1f6bffd5d9432f8cf 100644 (file)
@@ -10,6 +10,7 @@ describe('Helpers', function () {
     assert.deepStrictEqual(identifyLinkInQuery('https://www.openstreetmap.org/relation/1234#map=11/41.2388/-8.3867'), ['R', 1234]);
     assert.deepStrictEqual(identifyLinkInQuery('n1234'), ['N', 1234]);
     assert.deepStrictEqual(identifyLinkInQuery('W1234'), ['W', 1234]);
+    assert.deepStrictEqual(identifyLinkInQuery('R-123'), ['R', -123]);
   });
 
   it('.formatLabel', function () {