Skip to content
Merged
Changes from 2 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
24 changes: 21 additions & 3 deletions src/features/route/RoutePopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,24 @@ export function RoutePopup({ end, inline = false, ...props }) {
}

function DownloadRouteGPX({ route }) {
const escapeXml = (value = '') =>
String(value).replace(
/[<>&'"]/g,
(c) =>
({
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
"'": '&apos;',
'"': '&quot;',
})[c],
)

const sanitizeFilename = (name = '') =>
String(name)
.replace(/[\/:*?"<>|]/g, '')
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The sanitizeFilename function is missing the backslash character '' in the regex pattern. The current pattern [\/:*?"<>|] includes forward slash but not backslash, which is also an invalid filename character on Windows and should be removed. The pattern should be [\\/:*?"<>|] to include both forward slash and backslash.

Suggested change
.replace(/[\/:*?"<>|]/g, '')
.replace(/[\\/:*?"<>|]/g, '')

Copilot uses AI. Check for mistakes.
.slice(0, 200) || 'route'

const GPXContent = React.useMemo(() => {
if (!route.waypoints.length) {
return null
Expand All @@ -396,8 +414,8 @@ function DownloadRouteGPX({ route }) {
return `<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="ReactMap" xmlns="http://www.topografix.com/GPX/1/1">
<rte>
<name>${route.name}</name>
<desc>${route.description}</desc>
<name>${escapeXml(route.name)}</name>
<desc>${escapeXml(route.description)}</desc>
${route.waypoints
.map(
(waypoint) =>
Expand All @@ -417,7 +435,7 @@ function DownloadRouteGPX({ route }) {
href={`data:application/gpx;charset=utf-8,${encodeURIComponent(
GPXContent,
)}`}
download={`${route.name}.gpx`}
download={`${sanitizeFilename(route.name)}.gpx`}
size="small"
style={{ color: 'inherit' }}
>
Expand Down
Loading