Skip to content
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

fix parenthesis matching for JSON validation. #1763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alfy91
Copy link

@alfy91 alfy91 commented Oct 2, 2024

Issue description

In the JSON validator, there is a bug that occurs only for the closing parenthesis. For example, this JSON resource

{
  "resourceType": "Bundle",
  "type": "collection",
  "entry": [
    {
      "fullUrl": "urn:uuid:550e8400-e29b-41d4-a716-446655440000",
      "resource": {
        "resourceType": "Patient",
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": [
          {
            "use": "official",
            "family": "Robin",
            "given": ["Christopher"]
          ] /*<------- wrong parenthesis*/
        ]
      }
    }
  ]
}

Is considered correct from the validator, but in reality there is a wrong parenthesis ('}' is the correct one). This issue happens with any kind of special character, so also this JSON is considered correct by the validator:

{
  "resourceType": "Bundle",
  "type": "collection",
  "entry": [
    {
      "fullUrl": "urn:uuid:550e8400-e29b-41d4-a716-446655440000",
      "resource": {
        "resourceType": "Patient",
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": [
          {
            "use": "official",
            "family": "Robin",
            "given": ["Christopher"]
          # /*<------- wrong char*/
        ]
      }
    }
  ]
}

Proposed Solution

I added, in the JSONLexer, a check for the parenthesis matching. Through a stack, the parenthesis matching is checked, and the relative error is given.

This commit alfy91@29484b2
contains the details of the solution.

Copy link
Collaborator

@grahamegrieve grahamegrieve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you make any test cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants