Marshal.ts JIT crash on validation of keys with `:`, `-` or `#`
See original GitHub issueMinimal repro
// index.ts
import 'reflect-metadata';
import { validate, f } from '@marcj/marshal';
class Test {
constructor() {}
@f public 'some:prop'?: string;
}
const data = {
'some:prop': 'hello',
};
const validated = validate(Test, data);
will result in
jit code
return function(_data, _path, _errors) {
_path = _path ? _path + '.' : '';
_errors = _errors || [];
var value = _data.some:prop;
if (undefined !== value && null !== value) {
//property some:prop, string
if ('string' !== typeof value) _errors.push(new ValidationError(_path + 'some:prop', "invalid_string", "No string given"));
} else {
_errors.push(new ValidationError(_path + 'some:prop', 'required', 'Required value is undefined or null'));
}
return _errors;
}
/Users/hilkeheremans/projects/thinman/repro/node_modules/@marcj/marshal/src/jit-validation.ts:218
const compiled = new Function(...context.keys(), functionCode);
^
SyntaxError: Unexpected token ':'
at new Function (<anonymous>)
at Object.jitValidate (/Users/hilkeheremans/projects/thinman/repro/node_modules/@marcj/marshal/src/jit-validation.ts:218:58)
at Object.validate (/Users/hilkeheremans/projects/thinman/repro/node_modules/@marcj/marshal/src/validation.ts:97:12)
at Object.<anonymous> (/Users/hilkeheremans/projects/thinman/repro/src/index.ts:13:19)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Module.m._compile (/usr/local/Cellar/nvm/0.34.0/versions/node/v12.9.1/lib/node_modules/ts-node/src/index.ts:858:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Object.require.extensions.<computed> [as .ts] (/usr/local/Cellar/nvm/0.34.0/versions/node/v12.9.1/lib/node_modules/ts-node/src/index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
var value = _data.some:prop;
is probably to blame here, aka https://github.com/marcj/marshal.ts/blob/master/packages/core/src/jit-validation.ts#L192 ?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Marshal.ts - GitHub
Marshal is the by far fastest Javascript validation and serialization implementation to marshal JSON-representable data from JSON objects to ...
Read more >Untitled
Iiyama e2002wsv, Dumb love sean kingston hq, Santa key poem printable, Salat al sharq arabian oud, Lentil soup recipes with chicken, Mozdzanowo bursztyn, ......
Read more >Untitled
Accident maison ponthieu, Paaway kabayo, Dad's army story review, 02529 time table, 30 bmi and pregnant, Stv news baillieston, Regalos de halloween ...
Read more >Fix list for IBM WebSphere Application Server V8.5
IBM WebSphere Application Server provides periodic fixes for the base and Network Deployment editions of release V8.5. The following is a complete listing ......
Read more >MessagePack: It's like JSON. but fast and small.
... and data is always treated as suspect before it passes validation. ... If the file is missing or corrupt, if map keys...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just to let you know I am still on this, I hope to be submitting a PR sometime next week.
Alright. For me it’s not that big of an issue. I’ll close this issue so you can scratch this off your list of minor concerns. 😃
Thanks and looking forward to the release of deepkit!