tilemill-project / tilemill

TileMill is a modern map design studio
https://tilemill-project.github.io/tilemill/
BSD 3-Clause "New" or "Revised" License
3.12k stars 527 forks source link

cannot parse attribute name with single quote #1921

Closed leffjesh closed 8 years ago

leffjesh commented 11 years ago

Failed to parse expression: "([commonname] = 'Bird's-foot trefoil')" in style 'CCSWCD_Weed_Points' in Style at line 278

Using tillmill connect's style editor it creates CartoCSS that is not parse-able when copied into tilemill directly. example above. if i put a backslash in front of the tickmark (') it doesn't error out.

springmeyer commented 11 years ago

Hi @leffjesh - can you share the exact CSS that shows up in the style editor?

Also, can you share which TileMill version you are running?

leffjesh commented 11 years ago

TileMill version: 0.10.1

this style sheet errors out for me in tilemill. note there is now a different (contrived) case statement that errors out since my project has evolved. i can get the original if you want, but this one errors as well.

/* Generated by Arc2Earth Sync - TileMill Connect on 3/11/2013 5:49 PM  (725764461) */

#CCSWCD_Weed_Points {
    marker-opacity: 1;
    marker-allow-overlap: true;
    marker-placement: point;
    marker-clip: false;
    marker-file: url("C:\Users\jlesh\Documents\A2ESync\TileMill\Markers\6bcdfe2cd7f644959d2fcc05a8680065.svg");

.... snip ....
    [commonname = "Kudzu, Japanese arrowroot"] {
        marker-opacity: 1;
        marker-allow-overlap: true;
        marker-placement: point;
        marker-clip: false;
        marker-file: url("C:\Users\jlesh\Documents\A2ESync\TileMill\Markers\b0d221f33198462db3af2feb0118fd83.svg");
    }
    [commonname = "Purple Loosestrife's ERROR"] {
        marker-opacity: 1;
        marker-allow-overlap: true;
        marker-placement: point;
        marker-clip: false;
        marker-file: url("C:\Users\jlesh\Documents\A2ESync\TileMill\Markers\b8d2a69520f34bbaa9fe4e67409db215.svg");
    }
}
springmeyer commented 11 years ago

Thanks for the details. I've confirmed the bug in latest TileMill/Carto.

Screen Shot 2013-03-12 at 9 57 39 AM

springmeyer commented 11 years ago

/cc @tmcw @artemp - seems like this could be handled in one of two ways:

1) Carto could work harder to find embedded single quotes and escape them on the fly or 2) Mapnik could start supporting using double quotes to wrap attribute names, not just single quotes

springmeyer commented 11 years ago

Looks like carto can be easily fixed:

diff --git a/lib/carto/tree/quoted.js b/lib/carto/tree/quoted.js
index 3e70d99..134cf7f 100644
--- a/lib/carto/tree/quoted.js
+++ b/lib/carto/tree/quoted.js
@@ -8,7 +8,7 @@ tree.Quoted.prototype = {
     is: 'string',

     toString: function(quotes) {
-        var xmlvalue = this.value.replace(/\'/g, ''');
+        var xmlvalue = this.value.replace(/\'/g, "\\'");
         return (quotes === true) ? "'" + xmlvalue + "'" : this.value;
     },

But this would likely need to be modified to account for the user manually escaping.

strk commented 11 years ago

Can you check if this case is fixed by https://github.com/mapbox/carto/issues/263 ?