From 2b4c32807170bd1227d2f8fc7d36257913207770 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Wed, 12 Nov 2014 06:28:31 +0000 Subject: [PATCH] JSON Strings and GC Tokens .. fix json writing so that user metadata no longer conflicts with the tokens used by GoldenCheetah, e.g. a user entered "NM" in the workout code and that conflicted with the token used to delimit a torque value. .. all user strings are now saved with a space " " appended to the value and when read, if there is a trailing space it is removed. --- src/JsonRideFile.y | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/JsonRideFile.y b/src/JsonRideFile.y index 42cda45dd..fe5192c46 100644 --- a/src/JsonRideFile.y +++ b/src/JsonRideFile.y @@ -78,6 +78,9 @@ static QString protect(const QString string) s.replace("\f", "\\f"); // formfeed s.replace("/", "\\/"); // solidus + // add a trailing space to avoid conflicting with GC special tokens + s += " "; + return s; } @@ -91,6 +94,9 @@ static QString unprotect(const char * string) // in quotes. Lets strip those first QString s = string2.mid(1,string2.length()-2); + // does it end with a space (to avoid token conflict) ? + if (s.endsWith(" ")) s = s.mid(0, s.length()-1); + // now un-escape the control characters s.replace("\\t", "\t"); // tab s.replace("\\n", "\n"); // newline