Skip to content

Commit

Permalink
Test JSON value with an apostrophe
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Mar 13, 2019
1 parent ac96917 commit c70d16d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ public void jsonDataTypeTest()
.addRoundTrip(jsonDataType(), "null")
.addRoundTrip(jsonDataType(), "123.4")
.addRoundTrip(jsonDataType(), "\"abc\"")
.addRoundTrip(jsonDataType(), "\"text with \\\" quotations and ' apostrophes\"")
.addRoundTrip(jsonDataType(), "\"\"")
.addRoundTrip(jsonDataType(), "{\"a\":1,\"b\":2}")
.addRoundTrip(jsonDataType(), "{\"a\":[1,2,3],\"b\":{\"aa\":11,\"bb\":[{\"a\":1,\"b\":2},{\"a\":0}]}}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Optional;
import java.util.function.Function;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.padEnd;
import static com.google.common.io.BaseEncoding.base16;
import static io.prestosql.spi.type.CharType.createCharType;
Expand Down Expand Up @@ -157,16 +156,13 @@ public static DataType<String> jsonDataType()
return dataType(
"json",
JSON,
value -> {
checkArgument(!value.contains("'"));
return format("JSON '%s'", value);
},
value -> "JSON " + quote(value),
identity());
}

private static String quote(String value)
{
return "'" + value + "'";
return "'" + value.replace("'", "''") + "'";
}

/**
Expand Down

0 comments on commit c70d16d

Please sign in to comment.