Skip to content

Commit 25c63b5

Browse files
author
Leon Weidauer
committed
Fix length issue in OrderedMaps
Previously, a definiton with a 'length' property with numeric value would result in an OrderedMap of that length. This is now fixed and covered by tests
1 parent 8775c63 commit 25c63b5

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/core/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function fromJSOrdered (js) {
4141
return !isObject(js) ? js :
4242
Array.isArray(js) ?
4343
Im.Seq(js).map(fromJSOrdered).toList() :
44-
Im.Seq(js).map(fromJSOrdered).toOrderedMap()
44+
Im.OrderedMap(js).map(fromJSOrdered)
4545
}
4646

4747
export function bindToState(obj, state) {

test/core/utils.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-env mocha */
22
import expect from "expect"
33
import { fromJS } from "immutable"
4-
import { mapToList, validateNumber, validateInteger, validateParam, validateFile } from "core/utils"
4+
import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered } from "core/utils"
55
import win from "core/window"
66

7-
describe("utils", function(){
7+
describe("utils", function() {
88

99
describe("mapToList", function(){
1010

@@ -306,4 +306,31 @@ describe("utils", function(){
306306
expect( result ).toEqual( [{index: 0, error: "Value must be an integer"}, {index: 1, error: "Value must be an integer"}] )
307307
})
308308
})
309+
310+
describe("fromJSOrdered", () => {
311+
it("should create an OrderedMap from an object", () => {
312+
const param = {
313+
value: "test"
314+
}
315+
316+
const result = fromJSOrdered(param).toJS()
317+
expect( result ).toEqual( { value: "test" } )
318+
})
319+
320+
it("should not use an object's length property for Map size", () => {
321+
const param = {
322+
length: 5
323+
}
324+
325+
const result = fromJSOrdered(param).toJS()
326+
expect( result ).toEqual( { length: 5 } )
327+
})
328+
329+
it("should create an OrderedMap from an array", () => {
330+
const param = [1, 1, 2, 3, 5, 8]
331+
332+
const result = fromJSOrdered(param).toJS()
333+
expect( result ).toEqual( [1, 1, 2, 3, 5, 8] )
334+
})
335+
})
309336
})

0 commit comments

Comments
 (0)