From b9c17a9e9c687a8d9cc1f69ca6a417443b95dd1b Mon Sep 17 00:00:00 2001 From: soraefir Date: Thu, 24 Aug 2023 10:32:18 +0200 Subject: [PATCH] Fixing GPX parse error --- router/api.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/router/api.js b/router/api.js index 76408a8..58da83b 100644 --- a/router/api.js +++ b/router/api.js @@ -50,13 +50,18 @@ module.exports = (fastify, opts, done) => { let file = '' const data = JSON.parse(val); const gen_wpt = (name,desc,latlon,icon="Flag") => `0${name}-${desc}${icon}` + const esc_str = (str) => str.replace('"',""").replace("'","'").replace("<","<").replace(">",">").replace("&","&").repace("\n","...") + ' + < < + > > + & & data.main.forEach(a => { - file+= gen_wpt(a.hotel.name, a.hotel.notes.replace("\n","... ").replace("&","\\&"), a.hotel.latlon, icon="Hotel"); + file+= gen_wpt(esc_str(a.hotel.name), esc_str(a.hotel.notes), a.hotel.latlon, icon="Hotel"); a.places.restaurants.forEach(b => { - file+= gen_wpt(b.name, b.notes.replace("\n","... ").replace("&","\\&"), b.latlon, icon="Restaurant"); + file+= gen_wpt(esc_str(b.name), esc_str(b.notes), b.latlon, icon="Restaurant"); }); a.places.activities.forEach(b => { - file+= gen_wpt(b.name, b.notes.replace("\n","... ").replace("&","\\&"), b.latlon, icon="Tree"); + file+= gen_wpt(esc_str(b.name), esc_str(b.notes), b.latlon, icon="Tree"); }); }); file+="";