-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli/sql: \u0000 in JSON strings doesn't render properly (compared to psql) #33165
Comments
cc @knz |
Yep it does indeed look like |
This is surprisingly not a bug. Printing as |
@mjibson if pg reports an error on |
Where do we handle that properly? Go's
|
33221: sql: always use typed expressions for shift on int r=mjibson a=mjibson Previously the expressions 1 << 63 and 1::int << 63 would return positive and negative results, respectively. This was because constant folding in the first case is not subject to 2s complent that causes negative ints in the second case. Change shift on int to not fold. This prevents the surprising behavior described above in addition to other bugs where shifting by a large amount could allocate huge amounts of memory and crash the process. Fixes #32682 Release note (sql change): Shift operators on integers now always operate on explicit types instead of possibly an untyped constant. They also now return an error if the right-side operand is out of range. 33222: pgwire: test \u0001 in JSON pgwire encoding r=mjibson a=mjibson Verify that we handle "\u0001" JSON strings identically to postgres. The printing of \u0001 instead of some other character is correct, and the same as what postgres does. (We do not test \u0000 here because postgres rejects it as a valid string, even though we accept it.) Closes #33165 Release note: None Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
@mjibson unfortunately I think you have misunderstood the nature of the problem here. There are two layers of complexity: the conversion from the string the user enters to a SQL string. This unescapes Then there is a conversion of a SQL string to a JSON string. This re-escapes NUL characters to the JSON string I do think we need further investigation of the handling of the SQL -> JSON string conversion. |
I have investigated this further. The problem is in Using the
Then again
So the behavior is consistent between PostgreSQL and CockroachDB. However, the This is likely related to #31872. |
I have finished investigating this: the feature works as intended, and the weird display is a current (mis)feature of the SQL shell - one covered by #28756 and perhaps #31872. Long story short: both PostgreSQL and our JSONB parser accept to process and retain (in memory) special characters with a code < 32 (including On input special characters are accepted even if not escaped, for example The special chars are stored in-memory, as intended, as a single characters. However every time the JSONB is printed out - either via a direct conversion to string, or a conversion to byte array towards pgwire, any character with a code lower than 32 will get escaped using the I verified this to be true in both pg and CockroachDb. So far, so good. The final step is printing out the string to the screen/terminal.
I still have to figure out if this is an instance of a problem in In any case, both possible causes of the original symptoms are tracked by these separate issues, so I am going to close this one which has become redundant. |
Tried the following in
cockroach demo
on my Mac, with CockroachDB 2.1.1:While most Unicode escapes in JSON strings get encoded into UTF-8, it looks like "\u0000" isn't recognized that way. I would expect to see \u0000 show up as \x00 or something, as it does in other CockroachDB strings:
The text was updated successfully, but these errors were encountered: