Skip to content

Commit 6c21879

Browse files
committed
fix array rule return value issue (again).
1 parent 3e7c43d commit 6c21879

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
--------------------------------------------------
2-
<a name="1.0.0-beta3"></a>
3-
# 1.0.0-beta3 (2019-11-17)
2+
<a name="1.0.0-beta4"></a>
3+
# 1.0.0-beta4 (2019-11-17)
44

55
## Changes
66
- fix optional multi rule.
7+
- fix array rule return value issue (again).
78

89
--------------------------------------------------
910
<a name="1.0.0-beta2"></a>

lib/rules/array.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ module.exports = function({ schema, messages }, path, context) {
8787
*/
8888
src.push(`
8989
}
90-
91-
return value;
9290
`);
9391
}
9492

93+
src.push(`
94+
return value;
95+
`);
96+
9597
return {
9698
source: src.join("\n")
9799
};

test/rules/array.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ describe("Test rule: array", () => {
9393

9494
describe("Test sanitization", () => {
9595

96+
it("should untouch the checked obj", () => {
97+
let schema = {
98+
roles: { type: "array" }
99+
};
100+
let check = v.compile(schema);
101+
102+
const obj = {
103+
roles: ["admin", "user", "moderator"]
104+
};
105+
106+
expect(check(obj)).toEqual(true);
107+
expect(obj).toEqual({
108+
roles: ["admin", "user", "moderator"]
109+
});
110+
});
111+
96112
it("should trim all items", () => {
97113
let schema = {
98114
roles: { type: "array", items: "string|trim" }

test/typescript/rules/array.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ describe('TypeScript Definitions', () => {
9999

100100
describe("Test sanitization", () => {
101101

102+
it("should untouch the checked obj", () => {
103+
let schema = {
104+
roles: { type: "array" } as RuleArray
105+
};
106+
let check = v.compile(schema);
107+
108+
const obj = {
109+
roles: ["admin", "user", "moderator"]
110+
};
111+
112+
expect(check(obj)).toEqual(true);
113+
expect(obj).toEqual({
114+
roles: ["admin", "user", "moderator"]
115+
});
116+
});
117+
102118
it("should trim all items", () => {
103119
let schema = {
104120
roles: { type: "array", items: "string|trim" } as RuleArray

0 commit comments

Comments
 (0)