@@ -29,6 +29,7 @@ export default class JsonIncludePropertyFilter {
29
29
private static ALL_PROPERTIES_REGEX = / \* \* $ / g;
30
30
private static ALL_ELEMENT_PROPERTIES_REGEX = / \* $ / g;
31
31
private static ARRAY_INDEX = / \[ [ 0 - 9 ] + \] / g;
32
+ private static ARRAY_INDEX_START = / ^ \[ ( [ 0 - 9 ] + ) \] ./ ;
32
33
private static PATH_SEPARATOR = "." ;
33
34
private static STRING_EMPTY = "" ;
34
35
@@ -62,6 +63,10 @@ export default class JsonIncludePropertyFilter {
62
63
}
63
64
}
64
65
66
+ private _cleanupPath ( path : string ) {
67
+ return path . replace ( JsonIncludePropertyFilter . ARRAY_INDEX_START , "" ) ;
68
+ }
69
+
65
70
private _include ( rule : string , source : Array < string > , destination : Array < string > ) {
66
71
if ( rule . match ( JsonIncludePropertyFilter . ALL_PROPERTIES_REGEX ) ) {
67
72
this . _includeProperties ( rule , source , destination ) ;
@@ -72,11 +77,12 @@ export default class JsonIncludePropertyFilter {
72
77
}
73
78
}
74
79
75
- private _includeProperty ( rule : string , source : string , value : string , destination : Array < string > ) {
80
+ private _includeProperty ( rule : string , path : string , value : string , destination : Array < string > ) {
81
+ const cleanPath = this . _cleanupPath ( path ) ;
76
82
const regexp = `^${ rule } ` ;
77
83
78
- if ( source . match ( regexp ) ) {
79
- destination [ source ] = value ;
84
+ if ( cleanPath . match ( regexp ) ) {
85
+ destination [ path ] = value ;
80
86
}
81
87
}
82
88
@@ -95,7 +101,10 @@ export default class JsonIncludePropertyFilter {
95
101
const pathWithoutIndex = path . replace ( JsonIncludePropertyFilter . ARRAY_INDEX , JsonIncludePropertyFilter . STRING_EMPTY ) ;
96
102
97
103
if ( rule === JsonIncludePropertyFilter . STRING_EMPTY ) {
98
- if ( path . split ( JsonIncludePropertyFilter . PATH_SEPARATOR ) . length === 1 ) {
104
+ const cleanPath = this . _cleanupPath ( path ) ;
105
+ const splittedPath = cleanPath . split ( JsonIncludePropertyFilter . PATH_SEPARATOR ) ;
106
+
107
+ if ( splittedPath . length === 1 ) {
99
108
destination [ path ] = value ;
100
109
}
101
110
} else {
@@ -126,7 +135,8 @@ export default class JsonIncludePropertyFilter {
126
135
private _includeSpecificPath ( rule : string , source : Array < string > , destination : Array < string > ) {
127
136
for ( const path in source ) {
128
137
if ( path ) {
129
- const pathWithoutIndex = path . replace ( JsonIncludePropertyFilter . ARRAY_INDEX , JsonIncludePropertyFilter . STRING_EMPTY ) ;
138
+ const cleanPath = this . _cleanupPath ( path ) ;
139
+ const pathWithoutIndex = cleanPath . replace ( JsonIncludePropertyFilter . ARRAY_INDEX , JsonIncludePropertyFilter . STRING_EMPTY ) ;
130
140
const regexp = `^${ rule } ` ;
131
141
132
142
if ( pathWithoutIndex . match ( regexp ) ) {
0 commit comments