L.Util.getWKT = function(layer) {
    coord2str = function (obj) {
        if(obj.lng) return obj.lng + ' ' + obj.lat;
        if(obj.length === 0) return null;
        var n, c, wkt = [];
        for (n in obj) {
            c = coord2str(obj[n]);
            if (c) wkt.push(c);
        }
        return ("(" + String(wkt) + ")");
    };
    var coords = '()';
    if(layer.getLatLng) {
        coords = '(' + coord2str(layer.getLatLng()) + ')';
    }
    else if (layer.getLatLngs) {
        coords = coord2str(layer.getLatLngs());
    }
    var wkt = '';
    if (layer instanceof L.Marker) wkt += 'POINT'+coords;
    else if (layer instanceof L.Polygon) wkt += 'POLYGON('+coords+')';
    else if (layer instanceof L.MultiPolygon) wkt += 'MULTIPOLYGON('+coords+')';
    else if (layer instanceof L.Polyline) wkt += 'LINESTRING'+coords;
    else if (layer instanceof L.MultiPolyline) wkt += 'MULTILINESTRING('+coords+')';
    else {
        wkt += 'GEOMETRY'+coords;
    }
    return wkt;
};

@@ -31,382 +31,421 @@
 ) %7B%0A
+%0A
     
-coord2str = function (obj) %7B%0A        if(obj.lng) return obj.lng + ' ' + obj.lat;%0A        if(obj.length === 0) return null;%0A        var n, c, wkt = %5B%5D;%0A        for (n in obj) %7B%0A            c = coord2str(obj%5Bn%5D);%0A            if (c) wkt.push(c);%0A        %7D%0A        return (%22(%22 + String(wkt) + %22)%22)
+if (layer instanceof L.Marker)%0A        return 'POINT(' + coord2str(layer.getLatLng()) + ')';%0A    else if (layer instanceof L.Polygon) %7B%0A        var closed = layer.getLatLngs();%0A        if (!closed%5B0%5D.equals(closed%5Bclosed.length-1%5D)) %7B%0A            closed.push(closed%5B0%5D);%0A        %7D%0A        return 'POLYGON(' + coord2str(closed) + ')'
 ;%0A    %7D
-;
 %0A    
-var coords = '()';%0A   
+else
  if
+ 
 (layer
-.getLatLng) %7B%0A        coords = '(
+ instanceof L.Polyline)%0A        return 'LINESTRING
 ' + 
@@ -473,546 +473,300 @@
 tLng
+s
 ())
- + ')';%0A    %7D%0A    else if (layer.getLatLngs) %7B%0A        coords = coord2str(layer.getLatLngs());%0A    %7D%0A    var wkt = '';%0A
+;%0A    return 'GEOMETRY()';%0A%0A%0A     function coord2str(obj) %7B%0A     
    
- 
 if
- (layer instanceof L.Marker) wkt
+(obj.lng) return obj.lng
  +
-=
  '
-POINT'+coords;%0A    else if (layer instanceof L.Polygon) wkt += 'POLYGON('+coords+')';%0A    else if (layer instanceof L.MultiPolygon)
+ ' + obj.lat;%0A        if(obj.length === 0) return null;%0A        var n, c,
  wkt 
-+
 = 
-'MULTIPOLYGON('+coords+')';%0A    else if (layer instanceof L.Polyline) wkt += 'LINESTRING'+coords;%0A    else if (layer instanceof L.MultiPolyline) wkt += 'MULTILINESTRING('+coords+')';%0A    else %7B%0A        wkt += 'GEOMETRY'+coords
+%5B%5D;%0A        for (n in obj) %7B%0A            c = coord2str(obj%5Bn%5D);%0A            if (c) wkt.push(c)
 ;%0A    
+ 
-%7D%0A
+   %7D%0A    
     
@@ -776,12 +776,40 @@
 urn 
-wkt;
+(%22(%22 + String(wkt) + %22)%22);%0A    %7D
 %0A%7D;%0A

Fix WKT serialization of polygons (fixes #982)