Skip to content

Commit bb9d978

Browse files
committed
Bump version for 0.0.10
1 parent 6b268fe commit bb9d978

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Gemfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
requestjs-rails (0.0.9)
4+
requestjs-rails (0.0.10)
55
rails (>= 6.0.0)
66

77
GEM
@@ -140,4 +140,4 @@ DEPENDENCIES
140140
requestjs-rails!
141141

142142
BUNDLED WITH
143-
2.2.19
143+
2.3.22

app/assets/javascripts/requestjs.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function stringEntriesFromFormData(formData) {
105105
function mergeEntries(searchParams, entries) {
106106
for (const [name, value] of entries) {
107107
if (value instanceof window.File) continue;
108-
if (searchParams.has(name)) {
108+
if (searchParams.has(name) && !name.includes("[]")) {
109109
searchParams.delete(name);
110110
searchParams.set(name, value);
111111
} else {
@@ -143,6 +143,16 @@ class FetchRequest {
143143
headers[key] = value;
144144
this.options.headers = headers;
145145
}
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+
}
146156
get fetchOptions() {
147157
return {
148158
method: this.method.toUpperCase(),
@@ -154,12 +164,15 @@ class FetchRequest {
154164
};
155165
}
156166
get headers() {
157-
return compact(Object.assign({
167+
const baseHeaders = {
158168
"X-Requested-With": "XMLHttpRequest",
159-
"X-CSRF-Token": this.csrfToken,
160169
"Content-Type": this.contentType,
161170
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));
163176
}
164177
get csrfToken() {
165178
return getCookie(metaContent("csrf-param")) || metaContent("csrf-token");

lib/requestjs/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Requestjs
2-
VERSION = "0.0.9"
2+
VERSION = "0.0.10"
33
end

0 commit comments

Comments
 (0)