Comments (9)
I just tested dev-master with my schema + data and it works.. I'll never understand this godawful mess of backslashes. Thank you for the fix.
from php-json-schema-model-generator.
Digging, seems like this is quite an inconvenient problem to solve. My solution would be to embed the patterns as base64 blobs instead of as bare strings, and then generate code like preg_match(base64_decode('AAAAAAA==='))
instead, so that PHP string escaping doesn't get a chance to screw anything up.
from php-json-schema-model-generator.
Hi @dktapps
Thanks for the report! I'll have a look into it later.
from php-json-schema-model-generator.
After some testig I've adopted your idea of using encoded strings rather than the regular expression itself in the generated code. I've also added a test case including a regular expression with backslashes´and forward slashes to test escaping and the en-/decoding.
from php-json-schema-model-generator.
Additional escaping shouldn't be needed at all if you base64, no? It's only needed in the first place to prevent PHP interpreting it differently as a const string.
from php-json-schema-model-generator.
Yeah I thought the same way first but it's wrong (compare https://3v4l.org/YLRvS which matches a single backslash).
Also forward slashes must be escaped as they are used as delimiter of the regular expression.
from php-json-schema-model-generator.
In the sample I gave, the 4 backslashes are intended to match 1 backslash (JSON \\\\
resolves to \\
when decoded, passed to PCRE, which then turns it into literal \
). I'm just wondering if that might break something.
Also forward slashes must be escaped as they are used as delimiter of the regular expression.
preg_quote() might be better for that (specifically intended for purpose), though I don't suppose it matters much.
from php-json-schema-model-generator.
Yeah escaping is always hard, in this case on three layers. The JSON Schema, the PHP code and the PCRE engine. Glad it works now as expected.
from php-json-schema-model-generator.
I've thought about it again and you are absolutely right.
Four backslashes in the JSON mean two backslashes in the regular expression due to JSON escaping. Two backslashes in the regular expression must match one backslash in the tested string due to PCRE escaping. In the current implementation four backslashes in the JSON match two backslashes in the tested string which is wrong. It's so obscure.
But the delimiter escaping must be kept 😄
Edit: changed in 7dbf81a
from php-json-schema-model-generator.
Related Issues (20)
- Support for minContains and maxContains
- Make code output stable across multiple runs HOT 7
- Integer property with default 0 is incorrectly nullable HOT 3
- Validation of nested composition causes fatal error
- Access to undeclared property `_propertyValidationState` on simple templates HOT 3
- Incorrect native parameter type on nullable setters in mutable models HOT 5
- Crash on `"type": ["object"]` on object properties
- Inconsistency of generated code when using different methods to declare nullable structures HOT 1
- uuid string type support HOT 1
- No nested schema for composed property HOT 5
- Support number property key HOT 3
- Constructor with explicit argument HOT 1
- Add validateOption to FilterInterface
- ...PropertyProxy::getProperty(): Return value must be of type ...PropertyInterface, null returned in HOT 4
- Stable version HOT 1
- Filter for a property inside a Composition inside an array is not executed
- Error when generating classes with FedEx OpenAPI schema HOT 4
- Serialization Bug: Including Null Properties in JSON Output instead of Excluding Them HOT 1
- Creation of dynamic property for composed item validators on properties
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-json-schema-model-generator.