From 8a4f28b32105cb7790c52dd69f26df130a7cf51e Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sat, 19 Oct 2024 13:32:59 +0200 Subject: [PATCH] fix: CRLF issue --- index.html | 2 +- modules/io/load.js | 14 ++++++++++++-- versioning.js | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 1e2c4356..790a4d54 100644 --- a/index.html +++ b/index.html @@ -8119,7 +8119,7 @@ - + diff --git a/modules/io/load.js b/modules/io/load.js index bc9781fe..cd00b28c 100644 --- a/modules/io/load.js +++ b/modules/io/load.js @@ -153,11 +153,21 @@ async function uncompress(compressedData) { async function parseLoadedResult(result) { try { const resultAsString = new TextDecoder().decode(result); + // data can be in FMG internal format or base64 encoded const isDelimited = resultAsString.substring(0, 10).includes("|"); - const decoded = isDelimited ? resultAsString : decodeURIComponent(atob(resultAsString)); + let content = isDelimited ? resultAsString : decodeURIComponent(atob(resultAsString)); - const mapData = decoded.split("\r\n"); // split by CRLF + // fix if svg part has CRLF line endings instead of LF + const svgMatch = content.match(/]*id="map"[\s\S]*?<\/svg>/); + const svgContent = svgMatch[0]; + const hasCrlfEndings = svgContent.includes("\r\n"); + if (hasCrlfEndings) { + const correctedSvgContent = svgContent.replace(/\r\n/g, "\n"); + content = content.replace(svgContent, correctedSvgContent); + } + + const mapData = content.split("\r\n"); // split by CRLF const mapVersion = parseMapVersion(mapData[0].split("|")[0] || mapData[0] || ""); return {mapData, mapVersion}; diff --git a/versioning.js b/versioning.js index 025c183a..24c2f84a 100644 --- a/versioning.js +++ b/versioning.js @@ -12,7 +12,7 @@ * * Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2 */ -const VERSION = "1.105.16"; +const VERSION = "1.105.17"; if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function"); {