[GRASS-SVN] r69178 - grass/trunk/vector/v.what

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 21 07:07:22 PDT 2016


Author: annakrat
Date: 2016-08-21 07:07:21 -0700 (Sun, 21 Aug 2016)
New Revision: 69178

Modified:
   grass/trunk/vector/v.what/what.c
Log:
v.what: escape backslash in attributes for valid JSON, see #3133

Modified: grass/trunk/vector/v.what/what.c
===================================================================
--- grass/trunk/vector/v.what/what.c	2016-08-21 13:27:58 UTC (rev 69177)
+++ grass/trunk/vector/v.what/what.c	2016-08-21 14:07:21 UTC (rev 69178)
@@ -22,6 +22,7 @@
     int col, ncols, sqltype, more;
     char buf[5000];
     const char *colname;
+    char *formbuf;
     dbString sql, html, str;
     dbDriver *driver;
     dbHandle handle;
@@ -88,8 +89,10 @@
 
 	    G_debug(2, "%s: %s", colname, db_get_string(&str));
 	    if (json) {
+		formbuf = G_str_replace(db_get_string(&str), "\\", "\\\\");
 		sprintf(buf, "%s\"%s\": \"%s\"", col == 0 ? "" : ",\n",
-			colname, db_get_string(&str));
+			colname, formbuf);
+		G_free(formbuf);
 	    }
 	    else if (script)
 		sprintf(buf, "%s=%s\n", colname, db_get_string(&str));



More information about the grass-commit mailing list