-
-
Notifications
You must be signed in to change notification settings - Fork 1
Invalidates regular expressions when parsing the file #2
Comments
This is a bug in the schema, not in this library. As the error is telling you, the regular expression is invalid. Apparently node.js doesn't like it when you try to escape a character that shouldn't be escaped. In this case, that character appears to be |
Ha! I just assumed the regular expression was accurate, sorry! And actually, it is all the escaped characters that are troublesome 🧐 Weird none of the online validation tools does not complain about these... On a side note, why does a bundler need to parse regular expressions? 🤔 |
This won't have anything to do with the implementation because implementations don't implement their own regex engine. They use the one built into the platform they are running on. That's why all implementations will throw an error with this schema when running on node.js but not when running in a browser. It's because of the difference between the RegExp implementation used in browsers vs the one used in node.js. It has nothing to do with the JSON Schema implementation itself.
It doesn't, but that functionality came by default. Hyperjump JSC is built specifically to facilitate building tools like this. It compiles the schema into an AST that I can then use to build whatever tooling I want (validator, bundler, code gen, etc). By using that library to generate an AST, I was able to skip the hardest part of this implementation. Which is why I was able to put this together in an afternoon. But, that's also why there are some things in the AST building process that have nothing to do with bundlers. Those things are there for the benefit of other tools I've built or might build using the same AST (including a validator). |
Makes sense! Thanks for the clarification 🙂 Regarding the regex, I still can't wrap my head around why this ain't working, and what we can do to fix it, or where the problem lies 😆 This is the regex we try to build: https://regexr.com/69hcv, however when described in a JSON file we need to escape the If I run a small node example: // First test
const firstReg = new RegExp('^x-[\\w\\d\\.\\-\\_]+$', 'g');
const firstRes = firstReg.test('x-something');
console.log(firstRes);
// Second test
const secondReg = new RegExp('^x-[\w\d\.\-\_]+$', 'g');
const secondRes = secondReg.test('x-something');
console.log(secondRes); It produces:
The second regex is what the bundler tries to pass to So I am left puzzled 😆 |
I just figured out that browsers aren't working differently than node. The difference is the use of the Your failing test case should be, |
Thanks, @jdesrosiers! That should clear it up 🙇 |
While the file does not contain any
$ref
it fails to get the schema regardless, so it is the minimal reproducible example:Code that is being run:
The error being thrown:
The text was updated successfully, but these errors were encountered: