smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.02k stars 270 forks source link

Uncaught TypeError: t.trim is not a function #382

Closed gjvoosten closed 8 months ago

gjvoosten commented 8 months ago

After upgrading to the latest version 3.10.0, I am getting the following error: Screenshot from 2023-10-11 13-25-57

The reason for the exception appears to be that validateCoords(query) is called with an undefined query, so this change would fix it:

diff --git a/src/coords.ts b/src/coords.ts
index b874b8e..e413608 100644
--- a/src/coords.ts
+++ b/src/coords.ts
@@ -1,7 +1,7 @@
 // @ts-nocheck

 export function validateCoords(query) {
-  const q = query.trim();
+  const q = query?.trim();
   const regex = /^(-?[0-9]*\.?\s*[0-9]*)\s*,?\s*(-?[0-9]*\.?[0-9]*)$/g;
   const match = regex.exec(q);
   if (match) {
gjvoosten commented 8 months ago

Actually this issue isn't completely solved in v3.10.1; there is a difference between how validateCoords() is called while typing and after pressing Enter. While typing, it is called with the string that was typed in, and after pressing Enter, it is called with an object { query: this.searchElement.input.value, data: item } (see https://github.com/smeijer/leaflet-geosearch/blob/develop/src/SearchControl.ts#L332-L336 ).

I will raise a new issue. [edit: #384]