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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathToName from JSONSchemaBridge does not handle properties with whitespaces #909

Closed
ljmotta opened this issue Mar 23, 2021 · 2 comments 路 Fixed by #910
Closed

pathToName from JSONSchemaBridge does not handle properties with whitespaces #909

ljmotta opened this issue Mar 23, 2021 · 2 comments 路 Fixed by #910
Assignees
Labels
Type: Bug Bug reports and their fixes
Milestone

Comments

@ljmotta
Copy link

ljmotta commented Mar 23, 2021

Hi, this is my first issue here 馃榿 . I've came across of what I believe it is a bug on the JSONSchemaBridge. To be more precise, a bug on the pathToName method.

function pathToName(path: string) {
path = path.startsWith('.')
? path
.replace(/\['(.+?)'\]/g, '.$1')
.replace(/\[(.+?)\]/g, '.$1')
.replace(/\\'/g, "'")
: path.replace(/\//g, '.').replace(/~0/g, '~').replace(/~1/g, '/');
return path.slice(1);
}

As we can see on this piece of code on the last line, it performs a slice(1). This slice makes this method return a wrong string if you have a property that contains whitespace on the top level of your schema.

A property with whitespace is represented as "['My Property']" and a common property is ".myProperty".

Version: any (since the creation of this file)

An example of a schema that doesn't work correctly:

{
  type: "object",
  properties: {
    "My Property": {
      required: ["someValue"],
      type: "object",
      properties: {
        someValue: {
          type: "number"
        }
      }
    }
  }
}

The someValue property will not be validated correctly because pathToName will return "'My Property']" instead of "My Property" (I'm not sure if this should be the correct return, but it is what my tests suggest).

@radekmie radekmie self-assigned this Mar 24, 2021
@radekmie radekmie added the Type: Bug Bug reports and their fixes label Mar 24, 2021
@radekmie radekmie added this to Needs triage in Open Source (migrated) via automation Mar 24, 2021
@radekmie radekmie moved this from Needs triage to To do in Open Source (migrated) Mar 24, 2021
@radekmie radekmie added this to the v3.3 milestone Mar 24, 2021
@radekmie
Copy link
Contributor

Hi @ljmotta, thanks for the report! It looks like you are using the old format of ajv errors. Since v7 the default one is jsonPointers: true (to enable the old style in v7 use jsPropertySyntax: true). Here's a playground presenting this problem. Anyway, I agree we have to fix that.

@ljmotta
Copy link
Author

ljmotta commented Mar 24, 2021

@radekmie Thanks for addressing this issue so quickly! Yes I'm using an old format of ajv. My setup is ajv v6 (and ajv errors v1 due to compatibility) beucase my schema is draft4.

Open Source (migrated) automation moved this from In progress to Closed Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports and their fixes
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants