@@ -118,26 +118,21 @@ export function unflattenAttributes(
118
118
const result : Record < string , unknown > = { } ;
119
119
120
120
for ( const [ key , value ] of Object . entries ( obj ) ) {
121
- const parts = key
122
- . split ( / (?< ! \\ ) \. / ) // Split by unescaped dots
123
- . map ( unescapeKey ) // Unescape keys
124
- . reduce ( ( acc , part ) => {
125
- if ( part . startsWith ( "[" ) && part . endsWith ( "]" ) ) {
126
- // Handle array indices more precisely
127
- const match = part . match ( / ^ \[ ( \d + ) \] $ / ) ;
128
- if ( match && match [ 1 ] ) {
129
- acc . push ( parseInt ( match [ 1 ] ) ) ;
130
- } else {
131
- // Remove brackets for non-numeric array keys
132
- acc . push ( part . slice ( 1 , - 1 ) ) ;
133
- }
134
- } else {
135
- acc . push ( part ) ;
136
- }
137
- return acc ;
138
- } ,
139
- [ ] as ( string | number ) [ ]
140
- ) ;
121
+ const parts = key
122
+ . split ( '.' ) // Split by all dots
123
+ . reduce ( ( acc , part , i , arr ) => {
124
+ // If the previous part ends with an odd number of backslashes,
125
+ // the dot is escaped and should be part of the last segment.
126
+ if ( i > 0 && arr [ i - 1 ] . match ( / \\ + $ / ) ?. [ 0 ] ?. length % 2 === 1 ) {
127
+ acc [ acc . length - 1 ] += '.' + part ;
128
+ } else {
129
+ acc . push ( part ) ;
130
+ }
131
+ return acc ;
132
+ } , [ ] as ( string | number ) [ ] )
133
+ . map ( unescapeKey ) ; // Unescape keys
134
+ }
135
+ ) ;
141
136
142
137
let current : any = result ;
143
138
for ( let i = 0 ; i < parts . length - 1 ; i ++ ) {
0 commit comments