@@ -81,6 +81,11 @@ describe('.formatErrors(errors)', () => {
8181 const errors = [ { dataPath : 'arr[0].input' } ] ;
8282 expect ( helpers . formatErrors ( errors ) [ 0 ] . field ) . toStrictEqual ( 'arr.0.input' ) ;
8383 } ) ;
84+
85+ it ( 'should convert every array index when the path contains several' , ( ) => {
86+ const errors = [ { dataPath : 'items[0].tags[1]' } ] ;
87+ expect ( helpers . formatErrors ( errors ) [ 0 ] . field ) . toStrictEqual ( 'items.0.tags.1' ) ;
88+ } ) ;
8489} ) ;
8590
8691describe ( '.filterByFieldNameWithWildcard(fields, fieldName)' , ( ) => {
@@ -109,6 +114,30 @@ describe('.filterByFieldNameWithWildcard(fields, fieldName)', () => {
109114 expect ( helpers . filterByFieldNameWithWildcard ( fields , 'name*' ) )
110115 . toEqual ( [ { field : 'name' } , { field : 'name1' } ] ) ;
111116 } ) ;
117+
118+ it ( 'should treat the dot in a wildcard prefix as a literal character' , ( ) => {
119+ const fields = [
120+ { field : 'user.email' } ,
121+ { field : 'userX' } ,
122+ { field : 'user' } ,
123+ ] ;
124+
125+ expect ( helpers . filterByFieldNameWithWildcard ( fields , 'user.*' ) )
126+ . toEqual ( [ { field : 'user.email' } ] ) ;
127+ } ) ;
128+
129+ it ( 'should not crash when the wildcard prefix contains an unclosed bracket' , ( ) => {
130+ const fields = [
131+ { field : 'items[0].label' } ,
132+ { field : 'items[1].label' } ,
133+ { field : 'other' } ,
134+ ] ;
135+
136+ // The unescaped prefix `items[0` used to throw a SyntaxError
137+ // (unterminated character class) when compiled to a RegExp.
138+ expect ( helpers . filterByFieldNameWithWildcard ( fields , 'items[0*' ) )
139+ . toEqual ( [ { field : 'items[0].label' } ] ) ;
140+ } ) ;
112141} ) ;
113142
114143describe ( '.getInputCheckboxValue(target)' , ( ) => {
0 commit comments