Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-40709

JSON_QUERY returns a container out of a document that is broken, when the break lies past the matched path

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3, 13.0
    • None
    • JSON

    Description

      JSON_QUERY is documented to return NULL when it is not given a valid
      JSON document. Like its scalar sibling it stops at the matched path, so
      a break past the match is never met and the container is returned.

      SELECT JSON_QUERY('{"a":{"k":1} "b":2}', '$.a') AS v;
      v
      {"k":1}

      No warning. The outer document has no comma between its members and is
      not a JSON document.

      How to repeat

      -- the break is past the match: answered, silently
      SELECT JSON_QUERY('{"a":{"k":1} "b":2}', '$.a') AS v;   -- {"k":1}
      SELECT JSON_QUERY('{"a":{"k":1},"b":}', '$.a')  AS v;   -- {"k":1}
      SELECT JSON_QUERY('{"a":{"k":1}}}', '$.a')      AS v;   -- {"k":1}
       
      -- the break moved in front of the match: NULL
      SELECT JSON_QUERY('{"b":,"a":{"k":1}}', '$.a')  AS v;   -- NULL

      Root cause

      The same shape as the scalar form: the function returns at the match and
      the rest of the document is not read.

      Contract, `scripts/fill_help_tables.sql:457` (topic 383): *"Returns NULL
      if not given a valid JSON document, or if there is no match."*

      Affected versions

      JSON_QUERY was added in 10.2.3.

      Verified on 10.11 only (10.11.19-MariaDB-debug, commit 1dab253482d).
      Other branches were not tested.

      Note

      Found while auditing the JSON functions against their documented
      contracts. Partial. func_json_invalid.test:71 covers only
      '{"a":1,' and records NULL there for the unrelated reason that the
      path names a scalar. Nothing pins a broken document from which
      JSON_QUERY does hand back a container.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              arcivanov Arcadiy Ivanov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.