Skip to content

Commit

Permalink
Proper escaping for GeoJSON
Browse files Browse the repository at this point in the history
Fixes #101, #93
  • Loading branch information
clarisma committed Aug 26, 2023
1 parent 3a7e9fa commit c2af518
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion notices/README.TXT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Geographic Object Librarian (GOL) 0.1.7 EA
Geographic Object Librarian (GOL) 0.1.8-SNAPSHOT EA
==========================================

Copyright (c) Clarisma / GeoDesk contributors
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.geodesk</groupId>
<artifactId>gol-tool</artifactId>
<version>0.1.7</version>
<version>0.1.8-SNAPSHOT</version>
<packaging>jar</packaging>

<name>GeoDesk GOL Tool</name>
Expand All @@ -21,14 +21,14 @@
<dependency>
<groupId>com.geodesk</groupId>
<artifactId>geodesk</artifactId>
<version>0.1.7</version>
<version>0.1.8-SNAPSHOT</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/geodesk/gol/GolTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class GolTool extends Application
{
public static final String VERSION = "0.1.7";
public static final String VERSION = "0.1.8-SNAPSHOT";

@Override public String version()
{
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/geodesk/gol/query/GeoJsonFeaturePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ else if (g instanceof GeometryCollection)
}

// TODO: should string escaping happen in baseclass?
// No, different for each output type

@Override protected void printProperty(String key, String value)
{
Expand All @@ -151,21 +152,25 @@ else if (g instanceof GeometryCollection)
out.print(propertyNumber > 0 ? ",\"" : "\"");
out.print(key);
out.print("\":\"");
out.print(escapeValue(value));
out.print(Strings.escapeForJson(value));
out.print('\"');
return;
}
if(propertyNumber > 0) out.print(",\n");
out.print("\t\t\t\t\"");
out.print(key);
out.print("\": \"");
out.print(escapeValue(value));
out.print(Strings.escapeForJson(value));
out.print('\"');
}

// We can do simplified escaping (only quote and backslash) as all OSM
// strings have already been cleaned up during import, with unprintables
// turned into spaces
// (No, only dictionary strings are treated that way; must assume that we
// need to escape every string)
// Replaced with Strings.escapeForJson() to fix gol-tool#101
/*
private static String escapeValue(String s)
{
if(Strings.indexOfAny(s, "\"\\") < 0) return s;
Expand All @@ -188,6 +193,7 @@ private static String escapeValue(String s)
}
return buf.toString();
}
*/

private void printId(Feature feature)
{
Expand Down

0 comments on commit c2af518

Please sign in to comment.