Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json and escaping characters #10

Open
springmeyer opened this issue Aug 5, 2011 · 2 comments
Open

json and escaping characters #10

springmeyer opened this issue Aug 5, 2011 · 2 comments

Comments

@springmeyer
Copy link
Contributor

Mapnik XML can have linebreaks in strings, especially common in things like the sql subselects often used in the postgres 'table' parameter. These are ultimately stripped by mapnik before sending to postgres to avoid any issues: http://trac.mapnik.org/browser/trunk/include/mapnik/sql_utils.hpp#L58

Cascadenik uses XML for the mml and supports linebreaks as well:

https://github.com/mapnik/Cascadenik/blob/master/openstreetmap/style.mml#L97-105

But json need them to be escaped.

Also " can appear in sql selects, so those also need to be escaped.

@springmeyer
Copy link
Contributor Author

this solves the two issues I encountered where the output json was not valid, but surely we should find a better overall approach to escaping:

diff --git a/include/gen_layer.hpp b/include/gen_layer.hpp
index 23e7554..301b4a9 100644
--- a/include/gen_layer.hpp
+++ b/include/gen_layer.hpp
@@ -53,7 +53,13 @@ struct layer_data {

         style_names_ = rhs.styles();
         datasource_params_ = rhs.datasource()->params();
-        
+        boost::optional<std::string> table = datasource_params_.get<std::string>("table");
+        if (table) {
+            std::string table_val = *table;
+            boost::replace_all(table_val,"\n","\\n");
+            boost::replace_all(table_val,"\"","\\\"");
+            datasource_params_["table"] = table_val;
+        }

         if (rhs.title() != "")
             title_ = rhs.title();

@springmeyer
Copy link
Contributor Author

@rundel - any thoughts on this one? This is the only major blocker to converted the massive "osm.xml" at http://svn.openstreetmap.org/applications/rendering/mapnik/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant