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

Trailing garbage after a valid JSON value is accepted by JSON_LENGTH, JSON_QUERY, JSON_KEYS, JSON_VALUE, JSON_SEARCH and JSON_EXISTS

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • None
    • N/A
    • JSON
    • None
    • Not for Release Notes

    Description

      JSON_VALID rejects text with trailing garbage after a valid JSON value, but the reading functions silently accept it, and they also disagree with each other:

      Reproduced on 10.11.19 (debug build):

      SELECT JSON_VALID('1 x');                     -- 0
      SELECT JSON_LENGTH('1 x'),                    -- 1
             JSON_QUERY('[1] x', '$'),              -- [1]
             JSON_KEYS('{"a":1} x'),                -- ["a"]
             JSON_VALUE('{"a":1} x', '$.a');        -- 1
       
      SELECT JSON_SEARCH('["1"] x', 'one', '1'),    -- "$[0]"
             JSON_SEARCH('["1"] x', 'all', '1');    -- NULL (differs from 'one')
       
      SELECT JSON_EXISTS('[1] x', '$[0]'),                 -- 1
             JSON_CONTAINS_PATH('[1] x', 'one', '$[0]');   -- NULL (differs from JSON_EXISTS)

      Expected: like JSON_CONTAINS_PATH here, all of them treat the argument as invalid and return NULL.

      Related: MDEV-40703 (JSON_EXISTS answers 1 for the root path of a malformed document), MDEV-39933 (JSON_NORMALIZE on invalid data).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              chunlingqin chunlingqin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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