Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/views/document/utils/boxes/MapBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
</div>

<div class="buttons is-centered">
<a
v-if="geoUri && $screen.isMobile"
:href="geoUri"
class="button is-primary is-small"
:title="$gettext('Open this location in your map app')"
>
<fa-icon icon="map-marker-alt" />
</a>
<button v-if="showDownloadTraceButtons" class="button is-primary is-small" @click="downloadGpx">GPX</button>
<button v-if="showDownloadTraceButtons" class="button is-primary is-small" @click="downloadKml">KML</button>
<button
Expand Down Expand Up @@ -94,6 +102,23 @@ export default {
hasMapLinks() {
return (this.document.maps && this.document.maps.length !== 0) || this.document.maps_info;
},

geoUri() {
if (!this.document.geometry || !this.document.geometry.geom) {
return null;
}
let parsed;
try {
parsed = JSON.parse(this.document.geometry.geom);
} catch {
return null;
}
if (parsed.type !== 'Point' || !Array.isArray(parsed.coordinates)) {
return null;
}
const [lon, lat] = ol.proj.toLonLat(parsed.coordinates);
return `geo:${lat.toFixed(6)},${lon.toFixed(6)}?q=${lat.toFixed(6)},${lon.toFixed(6)}`;
Comment on lines +116 to +120
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard malformed coordinate values before building the URI.

Line 116–120 only checks that coordinates is an array; malformed values can still generate geo:NaN,NaN... and show a broken button instead of returning null.

Suggested fix
-      if (parsed.type !== 'Point' || !Array.isArray(parsed.coordinates)) {
+      if (parsed.type !== 'Point' || !Array.isArray(parsed.coordinates) || parsed.coordinates.length < 2) {
         return null;
       }
-      const [lon, lat] = ol.proj.toLonLat(parsed.coordinates);
+      const [x, y] = parsed.coordinates;
+      if (!Number.isFinite(x) || !Number.isFinite(y)) {
+        return null;
+      }
+      const [lon, lat] = ol.proj.toLonLat([x, y]);
+      if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
+        return null;
+      }
       return `geo:${lat.toFixed(6)},${lon.toFixed(6)}?q=${lat.toFixed(6)},${lon.toFixed(6)}`;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (parsed.type !== 'Point' || !Array.isArray(parsed.coordinates)) {
return null;
}
const [lon, lat] = ol.proj.toLonLat(parsed.coordinates);
return `geo:${lat.toFixed(6)},${lon.toFixed(6)}?q=${lat.toFixed(6)},${lon.toFixed(6)}`;
if (parsed.type !== 'Point' || !Array.isArray(parsed.coordinates) || parsed.coordinates.length < 2) {
return null;
}
const [x, y] = parsed.coordinates;
if (!Number.isFinite(x) || !Number.isFinite(y)) {
return null;
}
const [lon, lat] = ol.proj.toLonLat([x, y]);
if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
return null;
}
return `geo:${lat.toFixed(6)},${lon.toFixed(6)}?q=${lat.toFixed(6)},${lon.toFixed(6)}`;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/views/document/utils/boxes/MapBox.vue` around lines 116 - 120, The code
currently only checks Array.isArray(parsed.coordinates) and can produce geo:NaN
URIs; update the guard in the MapBox.vue logic that builds the URI (the block
referencing parsed.type, parsed.coordinates and ol.proj.toLonLat) to validate
coordinates thoroughly: require parsed.type === 'Point', ensure
parsed.coordinates is an array with at least two items, confirm the first two
entries are numeric (Number.isFinite) before calling ol.proj.toLonLat, and after
converting validate that lon and lat are finite numbers; if any check fails
return null. This targets the parsed.type/parsed.coordinates checks and the
ol.proj.toLonLat result to prevent generating geo:NaN URIs.

},
},

mounted() {
Expand Down
Loading