From f09bf40930e3a4e288bf8664713546bd1718eb91 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 5 Mar 2018 04:52:59 +0100 Subject: [PATCH] new cleaning strategy --- server.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/server.js b/server.js index cd410a6e4..1224b3a2d 100644 --- a/server.js +++ b/server.js @@ -683,6 +683,37 @@ function getGithubData(pOrg, pRepo, pPath, callBackFunction) { let decoded = atob(result.data.content); + /* + + This method usually brings up to 3 characters of encoding info at the begining of the JSON string which destroys the JSON format. + We will run the following code with the intention to eliminate this problem. + + */ + + let cleanString = decoded; + let jsonTest; + + try { + jsonTest = JSON.parse(cleanString); + } catch (err) { + cleanString = decoded.substring(1); + try { + jsonTest = JSON.parse(cleanString); + } catch (err) { + cleanString = decoded.substring(2); + try { + jsonTest = JSON.parse(cleanString); + } catch (err) { + cleanString = decoded.substring(3); + try { + jsonTest = JSON.parse(cleanString); + } catch (err) { + console.log("getGithubData -> onContent -> Could not clean the data received -> Data = " + decoded); + } + } + } + } + let cleanString = decoded.substring(2); // Eliminate first 2 bytes of ecoding info. githubData.set(pOrg + '.' + pRepo + '.' + pPath, cleanString);