fix: when detecting format, first apply the dollar->newline hack

This commit is contained in:
Paul Bienkowski 2020-11-19 17:48:45 +01:00
parent f890fc673f
commit f8bb6e7ab7

View file

@ -46,6 +46,8 @@ function addPointsToTrack(trackInfo, body, format = null) {
}
function detectFormat(body) {
body = replaceDollarNewlinesHack(body)
if (!body.length) {
return 'invalid';
}
@ -53,7 +55,9 @@ function detectFormat(body) {
const firstLinebreakIndex = body.indexOf('\n');
if (firstLinebreakIndex === -1) {
return 1;
// We need at least one linebreak in the whole file, to separate header and
// data. If the file contains no header, it is in valid.
return 'invalid'
}
const firstLine = body.substring(0, firstLinebreakIndex);
@ -63,6 +67,8 @@ function detectFormat(body) {
return Number(match[2]);
}
// If we have no metadata line, but start immediately with a header, it is
// format version 1.
if (/^Date;Time/.test(firstLine)) {
return 1;
}