js-routes 1.4.5 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e5ccc1ef3fef13c8d626f32e06cf99593acef814a7777aea3fb3d1452e1a92c
4
- data.tar.gz: 2a68dec293c58cd47939b8260da2a5038334d36fb72c3d967ec05088c46e039f
3
+ metadata.gz: e210567d580be40825a39c8fd5e13b15509f304f46e22909d6462e5fc1a1b817
4
+ data.tar.gz: 8c63da6abc92f0bc0478b3dba504151c42322253edf32c264137633d6469ccce
5
5
  SHA512:
6
- metadata.gz: '098b77abe8a1b7ade8c19b9adca75d51fef15d0ba17908e1f950b664a44cf5aa95bb12f3eea26c7e7112992db559ad1cb489116e47fe0728fc7f729d8788a96a'
7
- data.tar.gz: 492dec4811ae13841cd9a433bd313cd5677f2a31d941eea2463e940832067f2f744d79e080d8dba7e9effbe92f06b70641757919fc994118972690bff9fd2823
6
+ metadata.gz: f1515a6cd44bebc46459df4b404e4e839724aa5c5b8b4ded487f74a794592cef776666ed496dafdf4444c6cf9c672060efe44ed40c718952683dc748fd72c903
7
+ data.tar.gz: bd9e6b90de5410d71b1a98c490237962f25de377680994afdbfa0c27c19ce36ac049fc9d4a250a71a279517edb5b90a27fb75e3f4b0618ca5a42773612f17c3f
data/.travis.yml CHANGED
@@ -9,9 +9,8 @@ rvm:
9
9
  - 2.4.1
10
10
  - 2.5.3
11
11
  - 2.6.0
12
- - jruby-19mode
13
12
  - ruby-head
14
- - jruby-head
13
+ - jruby
15
14
 
16
15
  gemfile:
17
16
  - gemfiles/rails40_sprockets_2.gemfile
@@ -22,8 +21,10 @@ gemfile:
22
21
  - gemfiles/rails42_sprockets_3.gemfile
23
22
  - gemfiles/rails50_sprockets_3.gemfile
24
23
  - gemfiles/rails51_sprockets_3.gemfile
24
+ - gemfiles/rails52_sprockets_3.gemfile
25
25
 
26
26
  sudo: false
27
+ dist: xenial
27
28
 
28
29
  notifications:
29
30
  email:
@@ -34,10 +35,10 @@ branches:
34
35
  - master
35
36
 
36
37
  matrix:
38
+ fast_finish: true
37
39
  allow_failures:
38
- - rvm: jruby-19mode
39
40
  - rvm: ruby-head
40
- - rvm: jruby-head
41
+ - rvm: jruby
41
42
  exclude:
42
43
  - rvm: 2.6.0
43
44
  gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
data/Appraisals CHANGED
@@ -12,7 +12,8 @@ end
12
12
  [:rails41, '4.1.16', [2, 3]],
13
13
  [:rails42, '4.2.9', [2, 3]],
14
14
  [:rails50, '5.0.5', [3]],
15
- [:rails51, '5.1.3', [3]]
15
+ [:rails51, '5.1.3', [3]],
16
+ [:rails52, '5.2.3', [3]]
16
17
  ].each do |name, version, sprockets|
17
18
  define_appraisal(name, version, sprockets)
18
19
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## master
2
2
 
3
+ ## v1.4.6
4
+
5
+ * Fix regression of #244 in #243
6
+
3
7
  ## v1.4.5
4
8
 
5
9
  * Fix escaping inside route parameters and globbing #244
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "railties", "~> 5.2.3"
6
+ gem "sprockets", "~> 3.0"
7
+
8
+ gemspec :path => "../"
data/js-routes.gemspec CHANGED
@@ -31,6 +31,6 @@ Gem::Specification.new do |s|
31
31
  else
32
32
  s.add_development_dependency(%q<byebug>)
33
33
  s.add_development_dependency(%q<pry-byebug>)
34
- s.add_development_dependency(%q<therubyracer>, [">= 0.12.3"])
34
+ s.add_development_dependency(%q<mini_racer>, [">= 0.2.4"])
35
35
  end
36
36
  end
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.4.5"
2
+ VERSION = "1.4.6"
3
3
  end
data/lib/routes.js CHANGED
@@ -4,7 +4,7 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
4
4
  */
5
5
 
6
6
  (function() {
7
- var DeprecatedGlobbingBehavior, NodeTypes, ParameterMissing, ReservedOptions, SpecialOptionsKey, Utils, root,
7
+ var DeprecatedGlobbingBehavior, NodeTypes, ParameterMissing, ReservedOptions, SpecialOptionsKey, UriEncoderSegmentRegex, Utils, root,
8
8
  hasProp = {}.hasOwnProperty,
9
9
  slice = [].slice;
10
10
 
@@ -45,6 +45,8 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
45
45
 
46
46
  SpecialOptionsKey = SPECIAL_OPTIONS_KEY;
47
47
 
48
+ UriEncoderSegmentRegex = /[^a-zA-Z0-9\-\._~!\$&'\(\)\*\+,;=:@]/g;
49
+
48
50
  ReservedOptions = ['anchor', 'trailing_slash', 'subdomain', 'host', 'port', 'protocol'];
49
51
 
50
52
  Utils = {
@@ -283,7 +285,7 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
283
285
  value = parameters[left];
284
286
  delete parameters[left];
285
287
  if (value != null) {
286
- return encodeURIComponent(this.path_identifier(value));
288
+ return this.encode_segment(this.path_identifier(value));
287
289
  }
288
290
  if (optional) {
289
291
  return "";
@@ -295,6 +297,11 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
295
297
  throw new Error("Unknown Rails node type");
296
298
  }
297
299
  },
300
+ encode_segment: function(segment) {
301
+ return segment.replace(UriEncoderSegmentRegex, function(str) {
302
+ return encodeURIComponent(str);
303
+ });
304
+ },
298
305
  is_optional_node: function(node) {
299
306
  return this.indexOf([NodeTypes.STAR, NodeTypes.SYMBOL, NodeTypes.CAT], node) >= 0;
300
307
  },
data/lib/routes.js.coffee CHANGED
@@ -29,6 +29,7 @@ else
29
29
  NodeTypes = NODE_TYPES
30
30
  DeprecatedGlobbingBehavior = DEPRECATED_GLOBBING_BEHAVIOR
31
31
  SpecialOptionsKey = SPECIAL_OPTIONS_KEY
32
+ UriEncoderSegmentRegex = /[^a-zA-Z0-9\-\._~!\$&'\(\)\*\+,;=:@]/g # this is ActionDispatch::Journey::Router::Utils::UriEncoder::SEGMENT
32
33
 
33
34
  ReservedOptions = [
34
35
  'anchor'
@@ -212,7 +213,7 @@ Utils =
212
213
  value = parameters[left]
213
214
  delete parameters[left]
214
215
  if value?
215
- return encodeURIComponent(@path_identifier(value))
216
+ return @encode_segment(@path_identifier(value))
216
217
  if optional
217
218
  "" # missing parameter
218
219
  else
@@ -225,6 +226,7 @@ Utils =
225
226
  else
226
227
  throw new Error("Unknown Rails node type")
227
228
 
229
+ encode_segment: (segment) -> segment.replace(UriEncoderSegmentRegex, (str) -> encodeURIComponent(str))
228
230
 
229
231
  is_optional_node: (node) -> @indexOf([NodeTypes.STAR, NodeTypes.SYMBOL, NodeTypes.CAT], node) >= 0
230
232
 
@@ -401,7 +403,7 @@ Utils =
401
403
  routes.default_serializer = (object, prefix) ->
402
404
  Utils.default_serializer(object, prefix)
403
405
  Utils.namespace(root, NAMESPACE, routes)
404
-
406
+
405
407
  # Set up Routes appropriately for the environment.
406
408
  if typeof define is "function" and define.amd
407
409
  # AMD
@@ -14,15 +14,15 @@ describe JsRoutes, "compatibility with Rails" do
14
14
  expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
15
15
  end
16
16
 
17
- it "should raise error if required argument is not passed" do
17
+ it "should raise error if required argument is not passed", :aggregate_failures do
18
18
  expect { evaljs("Routes.thing_path()") }
19
- .to raise_error('Route parameter missing: id')
19
+ .to raise_error(/Route parameter missing: id/)
20
20
  expect { evaljs("Routes.search_path()") }
21
- .to raise_error('Route parameter missing: q')
21
+ .to raise_error(/Route parameter missing: q/)
22
22
  expect { evaljs("Routes.book_path()") }
23
- .to raise_error('Route parameter missing: title')
23
+ .to raise_error(/Route parameter missing: title/)
24
24
  expect { evaljs("Routes.book_title_path()") }
25
- .to raise_error('Route parameter missing: title')
25
+ .to raise_error(/Route parameter missing: title/)
26
26
  end
27
27
 
28
28
  it "should produce error stacktraces including function names" do
@@ -81,6 +81,16 @@ describe JsRoutes, "compatibility with Rails" do
81
81
  expect(evaljs("Routes.budgie_descendents_path(1)")).to eq(test_routes.budgie_descendents_path(1))
82
82
  end
83
83
 
84
+ it "should support route with parameters containing symbols that need URI-encoding", :aggregate_failures do
85
+ expect(evaljs("Routes.inbox_path('#hello')")).to eq(test_routes.inbox_path('#hello'))
86
+ expect(evaljs("Routes.inbox_path('some param')")).to eq(test_routes.inbox_path('some param'))
87
+ expect(evaljs("Routes.inbox_path('some param with more & more encode symbols')")).to eq(test_routes.inbox_path('some param with more & more encode symbols'))
88
+ end
89
+ it "should support route with parameters containing symbols not need URI-encoding", :aggregate_failures do
90
+ expect(evaljs("Routes.inbox_path(':some_id')")).to eq(test_routes.inbox_path(':some_id'))
91
+ expect(evaljs("Routes.inbox_path('.+')")).to eq(test_routes.inbox_path('.+'))
92
+ end
93
+
84
94
  describe "when route has defaults" do
85
95
  it "should support route default format" do
86
96
  expect(evaljs("Routes.api_purchases_path()")).to eq(test_routes.api_purchases_path)
@@ -115,9 +125,6 @@ describe JsRoutes, "compatibility with Rails" do
115
125
  it "should support route with parameters" do
116
126
  expect(evaljs("Routes.blog_app_post_path(1)")).to eq(blog_routes.post_path(1))
117
127
  end
118
- it "should support route with parameters containing symbols that need URI-encoding" do
119
- expect(evaljs("Routes.blog_app_post_path('#hello')")).to eq(blog_routes.post_path('#hello'))
120
- end
121
128
  it "should support root path" do
122
129
  expect(evaljs("Routes.blog_app_root_path()")).to eq(blog_routes.root_path)
123
130
  end
@@ -228,7 +235,7 @@ describe JsRoutes, "compatibility with Rails" do
228
235
 
229
236
  it "should raise error when passing non-full list of arguments and some query params" do
230
237
  expect { evaljs("Routes.thing_path(5, {q: 'hello'})") }
231
- .to raise_error('Route parameter missing: id')
238
+ .to raise_error(/Route parameter missing: id/)
232
239
  end
233
240
 
234
241
  it "should treat null as non-given optional part" do
@@ -246,7 +253,7 @@ describe JsRoutes, "compatibility with Rails" do
246
253
 
247
254
  context "and including them" do
248
255
  it "should fail when insufficient arguments are given" do
249
- expect { evaljs("Routes.thing_deep_path(2)") }.to raise_error('Route parameter missing: third_required')
256
+ expect { evaljs("Routes.thing_deep_path(2)") }.to raise_error(/Route parameter missing: third_required/)
250
257
  end
251
258
 
252
259
  it "should include the optional parts" do
data/spec/spec_helper.rb CHANGED
@@ -12,8 +12,8 @@ if defined?(JRUBY_VERSION)
12
12
  require 'rhino'
13
13
  JS_LIB_CLASS = Rhino
14
14
  else
15
- require 'v8'
16
- JS_LIB_CLASS = V8
15
+ require 'mini_racer'
16
+ JS_LIB_CLASS = MiniRacer
17
17
  end
18
18
 
19
19
  def jscontext(force = false)
@@ -25,7 +25,11 @@ def jscontext(force = false)
25
25
  end
26
26
 
27
27
  def js_error_class
28
- JS_LIB_CLASS::JSError
28
+ if defined?(JRUBY_VERSION)
29
+ JS_LIB_CLASS::JSError
30
+ else
31
+ JS_LIB_CLASS::Error
32
+ end
29
33
  end
30
34
 
31
35
  def evaljs(string, force = false)
@@ -89,25 +93,14 @@ RSpec.configure do |config|
89
93
  config.before :each do
90
94
  evaljs("var window = this;", true)
91
95
 
92
- def inspectify(value)
93
- case value
94
- when V8::Array
95
- value.map do |v|
96
- inspectify(v)
97
- end
98
- when V8::Object
99
- value.to_h.map do |k,v|
100
- [k, inspectify(v)]
101
- end.to_h
102
- when String, nil, Integer, FalseClass, TrueClass
103
- value
104
- else
105
- raise "wtf #{value.class}?"
96
+ if defined?(JRUBY_VERSION)
97
+ jscontext[:log] = lambda do |context, value|
98
+ puts value
106
99
  end
107
-
108
- end
109
- jscontext[:log] = lambda do |context, value|
110
- puts inspectify(value).to_json
100
+ else
101
+ jscontext.attach("log", proc do |value|
102
+ puts value
103
+ end)
111
104
  end
112
105
  end
113
106
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.5
4
+ version: 1.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-01 00:00:00.000000000 Z
11
+ date: 2019-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -123,19 +123,19 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: therubyracer
126
+ name: mini_racer
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 0.12.3
131
+ version: 0.2.4
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 0.12.3
138
+ version: 0.2.4
139
139
  description: Generates javascript file that defines all Rails named routes as javascript
140
140
  helpers
141
141
  email: agresso@gmail.com
@@ -163,6 +163,7 @@ files:
163
163
  - gemfiles/rails42_sprockets_3.gemfile
164
164
  - gemfiles/rails50_sprockets_3.gemfile
165
165
  - gemfiles/rails51_sprockets_3.gemfile
166
+ - gemfiles/rails52_sprockets_3.gemfile
166
167
  - js-routes.gemspec
167
168
  - lib/js-routes.rb
168
169
  - lib/js_routes.rb