1
1
import { describe , assert } from 'poku' ;
2
2
import { describeOptions } from '../../../common.test.cjs' ;
3
3
import getBinaryParser from '../../../../lib/parsers/binary_parser.js' ;
4
- import { srcEscape } from '../../../../lib/helpers.js' ;
5
4
import { privateObjectProps } from '../../../../lib/helpers.js' ;
6
5
7
6
describe ( 'Binary Parser: Block Native Object Props' , describeOptions ) ;
8
7
9
8
const blockedFields = Array . from ( privateObjectProps ) . map ( ( prop ) => [
10
- { name : prop } ,
9
+ { name : prop , table : '' } ,
11
10
] ) ;
12
11
13
12
blockedFields . forEach ( ( fields ) => {
@@ -17,8 +16,42 @@ blockedFields.forEach((fields) => {
17
16
} catch ( error ) {
18
17
assert . strictEqual (
19
18
error . message ,
20
- `The field name (${ srcEscape ( fields [ 0 ] . name ) } ) can't be the same as an object's private property.` ,
19
+ `The field name (${ fields [ 0 ] . name } ) can't be the same as an object's private property.` ,
21
20
`Ensure safe ${ fields [ 0 ] . name } ` ,
22
21
) ;
23
22
}
24
23
} ) ;
24
+
25
+ blockedFields
26
+ . map ( ( fields ) =>
27
+ fields . map ( ( field ) => ( { ...field , name : field . name . slice ( 1 ) } ) ) ,
28
+ )
29
+ . forEach ( ( fields ) => {
30
+ try {
31
+ getBinaryParser ( fields , { nestTables : '_' } , { } ) ;
32
+ assert . fail ( 'An error was expected' ) ;
33
+ } catch ( error ) {
34
+ assert . strictEqual (
35
+ error . message ,
36
+ `The field name (_${ fields [ 0 ] . name } ) can't be the same as an object's private property.` ,
37
+ `Ensure safe _${ fields [ 0 ] . name } for nestTables as string` ,
38
+ ) ;
39
+ }
40
+ } ) ;
41
+
42
+ blockedFields
43
+ . map ( ( fields ) =>
44
+ fields . map ( ( field ) => ( { ...field , name : '' , table : field . name } ) ) ,
45
+ )
46
+ . forEach ( ( fields ) => {
47
+ try {
48
+ getBinaryParser ( fields , { nestTables : true } , { } ) ;
49
+ assert . fail ( 'An error was expected' ) ;
50
+ } catch ( error ) {
51
+ assert . strictEqual (
52
+ error . message ,
53
+ `The field name (${ fields [ 0 ] . table } ) can't be the same as an object's private property.` ,
54
+ `Ensure safe ${ fields [ 0 ] . table } for nestTables as true` ,
55
+ ) ;
56
+ }
57
+ } ) ;
0 commit comments