@@ -105,7 +105,7 @@ function stringEntriesFromFormData(formData) {
105
105
function mergeEntries ( searchParams , entries ) {
106
106
for ( const [ name , value ] of entries ) {
107
107
if ( value instanceof window . File ) continue ;
108
- if ( searchParams . has ( name ) ) {
108
+ if ( searchParams . has ( name ) && ! name . includes ( "[]" ) ) {
109
109
searchParams . delete ( name ) ;
110
110
searchParams . set ( name , value ) ;
111
111
} else {
@@ -143,6 +143,16 @@ class FetchRequest {
143
143
headers [ key ] = value ;
144
144
this . options . headers = headers ;
145
145
}
146
+ sameHostname ( ) {
147
+ if ( ! this . originalUrl . startsWith ( "http:" ) ) {
148
+ return true ;
149
+ }
150
+ try {
151
+ return new URL ( this . originalUrl ) . hostname === window . location . hostname ;
152
+ } catch ( _ ) {
153
+ return true ;
154
+ }
155
+ }
146
156
get fetchOptions ( ) {
147
157
return {
148
158
method : this . method . toUpperCase ( ) ,
@@ -154,12 +164,15 @@ class FetchRequest {
154
164
} ;
155
165
}
156
166
get headers ( ) {
157
- return compact ( Object . assign ( {
167
+ const baseHeaders = {
158
168
"X-Requested-With" : "XMLHttpRequest" ,
159
- "X-CSRF-Token" : this . csrfToken ,
160
169
"Content-Type" : this . contentType ,
161
170
Accept : this . accept
162
- } , this . additionalHeaders ) ) ;
171
+ } ;
172
+ if ( this . sameHostname ( ) ) {
173
+ baseHeaders [ "X-CSRF-Token" ] = this . csrfToken ;
174
+ }
175
+ return compact ( Object . assign ( baseHeaders , this . additionalHeaders ) ) ;
163
176
}
164
177
get csrfToken ( ) {
165
178
return getCookie ( metaContent ( "csrf-param" ) ) || metaContent ( "csrf-token" ) ;
0 commit comments