Skip to content

Commit 96805e8

Browse files
committed
Fixes #336
1 parent d8c3a13 commit 96805e8

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [2.3.7]
4+
5+
* Fixed serialization of empty `Array` and empty `Hash`. Fixes [#336](https://github.com/railsware/js-routes/issues/336).
6+
7+
``` javascript
8+
blog_path({filters: {}, columns: []}) // => /blog
9+
```
10+
311
## [2.3.6]
412

513
* Support new Rails 8.1 nil parameter serialization.

lib/routes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ RubyVariables.WRAPPER(
140140
if (prefix) {
141141
key = prefix + "[" + key + "]";
142142
}
143-
result.push(this.default_serializer(prop, key));
143+
const subvalue = this.default_serializer(prop, key);
144+
if (subvalue.length) {
145+
result.push(subvalue);
146+
}
144147
}
145148
}
146149
else {

lib/routes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ RubyVariables.WRAPPER(
263263
if (prefix) {
264264
key = prefix + "[" + key + "]";
265265
}
266-
result.push(this.default_serializer(prop, key));
266+
const subvalue = this.default_serializer(prop, key);
267+
if (subvalue.length) {
268+
result.push(subvalue);
269+
}
267270
}
268271
} else {
269272
result.push(

spec/js_routes/rails_routes_compatibility_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@
191191
expectjs("Routes.inbox_path(1, {hello: ['world', 'mars']})").to eq(test_routes.inbox_path(1, :hello => [:world, :mars]))
192192
end
193193

194+
it "should support empty array get parameters" do
195+
expectjs("Routes.inboxes_path({ a: [], b: {} })").to eq(test_routes.inboxes_path({ a: [], b: {} }))
196+
end
197+
194198
context "object without prototype" do
195199
before(:each) do
196200
evaljs("let params = Object.create(null); params.q = 'hello';")

0 commit comments

Comments
 (0)