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

3.1.0 Release fails to validate strings via regex #612

Closed
amisevsk opened this issue Oct 9, 2019 · 11 comments
Closed

3.1.0 Release fails to validate strings via regex #612

amisevsk opened this issue Oct 9, 2019 · 11 comments
Labels
Bug Something doesn't work the way it should. Needs Test Upstream Issues that need to have a test added to https://github.com/json-schema-org/JSON-Schema-Test-Suite

Comments

@amisevsk
Copy link

amisevsk commented Oct 9, 2019

A CI build of ours pulled the new release (3.1.0) and all validation is failing with messages like

u'go' does not match u'^[^\\s]+$'

Building with <3.1.0 does not have this issue.

Reproducer:

test.json:

{
  "test": "testString"
}

schema.json;

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Reproducer",
  "type": "object",
  "properties": {
    "test": {
      "type": "string",
      "pattern": "^[^\\s]+$"
    }
  }
}

dockerfile (or just install 3.1.0 locally)

FROM alpine:3.10
RUN apk add --no-cache py-pip jq && pip install jsonschema

COPY . /build
RUN jsonschema --version
RUN jsonschema /build/schema.json -i /build/test.json
@Julian Julian added the Bug Something doesn't work the way it should. label Oct 9, 2019
@Julian
Copy link
Member

Julian commented Oct 9, 2019

Having a look...

@amisevsk
Copy link
Author

amisevsk commented Oct 9, 2019

Thanks @Julian, from a somewhat hasty check, looks to be related to character classes ("^[^ \t]+$" does not have the issue)

@dslagle
Copy link

dslagle commented Oct 9, 2019

This appears to be related to the switch to js_regex. Specifically in relation to character classes where something like [\w0-9] gets translated to [[a-zA-Z]0-9] inside js_regex. At least that's what happened in my case.

@Julian
Copy link
Member

Julian commented Oct 9, 2019

OK, given that there's 2 separate issues here (#612 and #611) and that this is fairly fundamental functionality, I've temporarily pushed out v3.1.1 reverting the switchover.

We'll add some tests for the two cases here (and anything else we missed), and then there likely will be a v3.1.2 that goes back again to js-regex again.

@Zac-HD
Copy link
Member

Zac-HD commented Oct 9, 2019

This appears to be related to the switch to js_regex. Specifically in relation to character classes where something like [\w0-9] gets translated to [[a-zA-Z]0-9] inside js_regex.

Yep, that's a bug in js-regex. Sorry for the trouble this has caused everyone 😕

@amisevsk
Copy link
Author

Thanks all, FWIW I re-read the jsonschema draft docs and it does suggest not using anything outside of pretty limited range of the regex spec, so my issues are partly my own doing ;)

@Julian Julian added the Needs Test Upstream Issues that need to have a test added to https://github.com/json-schema-org/JSON-Schema-Test-Suite label Jun 20, 2020
@tschmidtb51
Copy link

@Julian: What is the current status on that issue? Does jsonschema still use js_regex?

@Julian
Copy link
Member

Julian commented Jun 17, 2021

No, newer releases are not using js-regex. We still may explore JS regexes in the future, but yeah this issue shouldn't be present.

@Julian Julian closed this as completed Jun 17, 2021
@tschmidtb51
Copy link

tschmidtb51 commented Jun 17, 2021

The problem that js_regex tried to solve is still there, correct?

Did you know that regular expressions may vary between programming languages? For example, let's consider the pattern "^abc$", which matches the string "abc". But what about the string "abc\n"? It's also matched in Python, but not in Javascript!

@Julian
Copy link
Member

Julian commented Jun 17, 2021

Yes, today we support only Python regular expressions.

@tschmidtb51
Copy link

Thanks for clarifying.

Julian added a commit that referenced this issue Nov 28, 2022
78c888273 Merge pull request #618 from json-schema-org/gregsdennis/contentschema-should-fail-content
5cbc53bc0 Merge pull request #613 from santhosh-tekuri/rjp-multidigit
bb000ce98 Merge pull request #620 from json-schema-org/ether/remove-unused-remotes
c4c490f1d Merge pull request #617 from json-schema-org/gregsdennis/dynamicAnchor-inside-propertyDependencies
0189831a9 remove schemas that are never referenced
cf1b94249 Merge pull request #610 from handrews/rm-remotes
d6490e817 move anchors into defs
2f9d117c0 Merge pull request #616 from json-schema-org/gregsdennis/propertyDependencies-and-unevaluated
4e5649cd0 move tests to draft-next
a41f2f6c4 added type:object to contentSchema schemas
2f50e7864 add tests for $dynamicAnchor in multiple branches of propertyDependencies
4794a1991 add tests for unevaluatedProperties seeing inside propertyDependencies
27cc299f3 Add RJP test 'multi-digit integer prefix'
716b95d94 Merge pull request #612 from santhosh-tekuri/rjp-positive
320c804d1 Add RJP test 'explicit positive prefix'
c8f210c39 Merge pull request #611 from santhosh-tekuri/time-alpha
3faeb222d add time test 'contains letters'
642441f2d Merge pull request #603 from santhosh-tekuri/uuid-nonstr
94d5043c7 add non-string uri tests
0c81374a2 Remove unneeded remotes
97a3e2156 Merge pull request #608 from json-schema-org/json-everything-uses-the-test-suite
bdaf7e8be added json-everything to 'who uses' section of readme; removed manatee.json (deprecated)
f00ec1008 Merge pull request #606 from santhosh-tekuri/duration-nounit
134480721 Merge pull request #607 from santhosh-tekuri/time-offsetprefix
dd4538eee Test time format 'offset not starting with plus or minus'
80fe2db15 test duration format 'element without unit'
38ea15116 Merge pull request #604 from santhosh-tekuri/time-offset
613ec170e second fraction, not offset
ee4bd4eb6 Add time format test with second fraction, no offset
86c2517cd Merge pull request #605 from santhosh-tekuri/rjp-empty
cfe80006a Add relative-json-pointer test with empty string
31796b3b8 add non-string uuid tests

git-subtree-dir: json
git-subtree-split: 78c8882732bcdc2dad81cd7ce1e3f9bca6fb7a9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something doesn't work the way it should. Needs Test Upstream Issues that need to have a test added to https://github.com/json-schema-org/JSON-Schema-Test-Suite
Projects
None yet
Development

No branches or pull requests

5 participants