Re: [sqlite] Backslash problems with json() and json_valid()

2016-11-07 Thread Dominique Devienne
On Mon, Nov 7, 2016 at 6:49 AM, Øyvind A. Holm  wrote:

> It seems as json() and json_valid() misbehave about unescaped
> backslashes. json() creates invalid JSON, and json_valid() happily
> accepts it:
>
>   $ sqlite3
>   SQLite version 3.15.1 2016-11-04 12:08:49
>   Enter ".help" for usage hints.
>   Connected to a transient in-memory database.
>   Use ".open FILENAME" to reopen on a persistent database.
>   sqlite> select json('" \ "'); -- Creates invalid JSON
>   " \ "
>   sqlite> select json('" \\ "');
>   " \\ "
>   sqlite> select json_valid('" \ "'); -- Accepts invalid JSON
>   1
>   sqlite> select json_quote('\'); -- Works correctly
>   "\\"
>   sqlite>
>
>   $ sqlite3 :memory: "select json('\" \\ \"');"
>   " \ "
>   $ sqlite3 :memory: "select json('\" \\ \"');" | json_verify
>   lexical error: inside a string, '\' occurs before a character which it
>   may not.
>   " \ "
>(right here) --^
>   JSON is invalid
>   $
>
> It's been like this since JSON arriveed in v3.9.0.
>

Just a couple precisions, to help read Øyvind's post:

1) SQLite doesn't do C-style escapes.

From https://www.sqlite.org/lang_expr.html :
  "C-style escapes using the backslash character are not supported because
they are not standard SQL."

2) The last two commands are hard to parse because of the need to do
shell-escaping.

But otherwise I believe he's correct. Only the following chars can follow a
backslash in JSON: u " \ / b f n r t

--DD
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Backslash problems with json() and json_valid()

2016-11-06 Thread Øyvind A . Holm
It seems as json() and json_valid() misbehave about unescaped
backslashes. json() creates invalid JSON, and json_valid() happily
accepts it:

  $ sqlite3
  SQLite version 3.15.1 2016-11-04 12:08:49
  Enter ".help" for usage hints.
  Connected to a transient in-memory database.
  Use ".open FILENAME" to reopen on a persistent database.
  sqlite> select json('" \ "'); -- Creates invalid JSON
  " \ "
  sqlite> select json('" \\ "');
  " \\ "
  sqlite> select json_valid('" \ "'); -- Accepts invalid JSON
  1
  sqlite> select json_quote('\'); -- Works correctly
  "\\"
  sqlite>

  $ sqlite3 :memory: "select json('\" \\ \"');"
  " \ "
  $ sqlite3 :memory: "select json('\" \\ \"');" | json_verify
  lexical error: inside a string, '\' occurs before a character which it
  may not.
  " \ "
   (right here) --^
  JSON is invalid
  $

It's been like this since JSON arriveed in v3.9.0.

And oh, thanks for creating this wonderful piece of software.

Regards,
Øyvind
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users