File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed
Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
88## [ Unreleased]
99
10+ ### Fixed
11+
12+ - Bug with ` optional ` rule that ignores validation when an empty string is passed ([ #149 ] ( https://github.com/imbrn/v8n/issues/149 ) )
13+
1014## [ 1.3.0] - 2019-05-19
1115
1216### Added
Original file line number Diff line number Diff line change @@ -176,8 +176,9 @@ const availableRules = {
176176 validations . some ( validation => validation . test ( value ) ) ,
177177
178178 optional : ( validation , considerTrimmedEmptyString = false ) => value => {
179- if ( typeof value === "string" && value . trim ( ) === "" )
180- return considerTrimmedEmptyString ;
179+ if ( considerTrimmedEmptyString )
180+ return typeof value === "string" && value . trim ( ) === "" ;
181+
181182 if ( value !== undefined && value !== null ) validation . check ( value ) ;
182183 return true ;
183184 }
Original file line number Diff line number Diff line change @@ -1175,6 +1175,12 @@ describe("rules", () => {
11751175 expect ( optional . test ( 1 ) ) . toBe ( true ) ;
11761176 expect ( optional . test ( 2 ) ) . toBe ( true ) ;
11771177 expect ( optional . test ( 1000 ) ) . toBe ( true ) ;
1178+
1179+ expect (
1180+ v8n ( )
1181+ . optional ( v8n ( ) . string ( ) )
1182+ . test ( "" )
1183+ ) . toBe ( true ) ;
11781184 } ) ;
11791185
11801186 it ( "should fail when validation fails" , ( ) => {
You can’t perform that action at this time.
0 commit comments