Gregory Hart created CALCITE-5088:
-------------------------------------

             Summary: Generated model should escape backslashes
                 Key: CALCITE-5088
                 URL: https://issues.apache.org/jira/browse/CALCITE-5088
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.28.0
            Reporter: Gregory Hart


When a model is generated (because one is not provided in the JDBC URL), the 
generated JSON does not properly escape backslashes.

Example in pseudo-code:
{code:java}
Properties info = new Properties();
info.setProperty("schema.jdbcUrl", "jdbc:mssql://host\\THEDB:1443");
DriverManager.getConnection("jdbc:calcite:", info); 
{code}
Expected result:

The connection is opened successfully.

Actual result:

com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 
'T' (code 84)
at [Source: (String)"{
...
"jdbcUrl": "jdbc:mssql://host\THEDB:1443"
...
at org.apache.calcite.model.ModelHandler.<init>(ModelHandler.java:101)
at org.apache.calcite.jdbc.Driver$1.onConnectionInit(Driver.java:101)

Possible fix:

Add the following to 
org.apache.calcite.util.JsonBuilder.append(JsonBuilder.java:95). This will fix 
backslashes but there may be other characters that need to be escaped too.
{code:java}
.replace("\\", "\\\\")
{code}
[https://github.com/apache/calcite/blob/calcite-1.28.0/core/src/main/java/org/apache/calcite/util/JsonBuilder.java#L95]

It looks like it's being called by 
org.apache.calcite.jdbc.Driver$1.model(Driver.java:153).



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to