batch of fixes

This commit is contained in:
vcoppe committed 2026-11-04 21:27:14 +01:00
1 parent a67b982b1c
commit eee76f05d4
9 files changed
+288 -66

No files matched your search

@@ -95,6 +95,21 @@ describe('legacyFileToGPX', () => {
assert.ok(gpx.includes('href="https://example.com/?a="1"&b=2"'));
});
it('writes all the links of an element', () => {
const links = [
{ attributes: { href: 'https://a.example/' }, text: 'first' },
{ attributes: { href: 'https://b.example/' } },
];
const gpx = legacyFileToGPX({
metadata: { name: 'x', link: links },
trk: [{ link: links, trkseg: [] }],
});
const written =
'<link href="https://a.example/"><text>first</text></link><link href="https://b.example/"></link>';
assert.ok(gpx.includes(`<name>x</name>${written}</metadata>`));
assert.ok(gpx.includes(`<trk>${written}</trk>`));
});
it('leaves out what is missing or empty', () => {
const gpx = legacyFileToGPX({
metadata: { name: '', desc: null, time: 'not a date' },
+4
View File
@@ -84,7 +84,11 @@ function timeElement(value: unknown): string {
return isNaN(date.getTime()) ? '' : element('time', date.toISOString());
}
/** The link of an element, or the links: the former parser gave a list when there were several. */
function link(value: Json): string {
if (Array.isArray(value)) {
return value.map(link).join('');
}
const href = value?.attributes?.href;
return href
? `<link href="${escape(href).replaceAll('"', '&quot;')}">${element('text', value.text)}</link>`