requestjs-rails 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14d1461644aa9f865df4f57cecd1060168040d64484259f128658516ddf7c7f4
4
- data.tar.gz: 2c63e6568c07bdee1c89f4bf5f931e66f9dc4f6bdc967ccd3e7018cae68870f3
3
+ metadata.gz: 3cfa027194b10b71958ba06f76e28d181ab6df698cbe26afd29295aec86146b5
4
+ data.tar.gz: 757283047d0579f8e32f8556b90e2b4e24bcda160590cd8de677ba64eb26e88e
5
5
  SHA512:
6
- metadata.gz: 67a2f0495e24ed4d5a714b3cbad2017f3b04934a21778570b4ec56d7b4fa596f857fbaea8bf1b60550aae34b94252fd68bdb499c6637b2e95aea4a5594c46128
7
- data.tar.gz: 3ecef3f8ea92142184953c3225df5f23e3e8e85b667068c72322a1003e795685b704b1c8c3bddf7f355ca1c6b748d975453b47a02137d49990a0f0e1d298acdd
6
+ metadata.gz: 9c12ab260f0c0a403c2c2666e35386f72c7637e5c33d71a312bf335ad02c90a261b544b211c3b30bdf06ba19fed84a458e77ac8cadb165482d4e44f7bc03b0fa
7
+ data.tar.gz: c0c5a9d7c6cb5963626672fe2866112fce7a75e11c6baf4edb942d27ff507a23499fda5d3d2f553d942b417ba65ab047ccebac449fbb8357110313de37ed8f54
@@ -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");
@@ -1,3 +1,3 @@
1
1
  module Requestjs
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requestjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Lauxen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.2.19
64
+ rubygems_version: 3.1.6
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: A tiny Fetch API wrapper that allows you to make http requests without need