@@ -98,32 +98,29 @@ internals.String = class extends Any {
9898 const patternObject = {
9999 pattern : new RegExp ( pattern . source , pattern . ignoreCase ? 'i' : undefined ) // Future version should break this and forbid unsupported regex flags
100100 } ;
101- let patternIsInverted = false ;
102101
103102 if ( typeof patternOptions === 'string' ) {
104103 patternObject . name = patternOptions ;
105104 }
106105 else if ( typeof patternOptions === 'object' ) {
107- patternIsInverted = ! ! patternOptions . invert ;
108- patternObject . invert = patternIsInverted ;
106+ patternObject . invert = ! ! patternOptions . invert ;
109107
110108 if ( patternOptions . name ) {
111109 patternObject . name = patternOptions . name ;
112110 }
113111 }
114112
115- const baseRegex = patternIsInverted ? 'string.regex.inverted' : 'string.regex.base' ;
116- const nameRegex = patternIsInverted ? 'string.regex.invertedName' : 'string.regex.name' ;
113+ const errorCode = [ 'string.regex' , patternObject . invert ? '.invert' : '' , patternObject . name ? '.name' : '.base' ] . join ( '' ) ;
117114
118115 return this . _test ( 'regex' , patternObject , function ( value , state , options ) {
119116
120117 const patternMatch = patternObject . pattern . test ( value ) ;
121118
122- if ( patternMatch ^ patternIsInverted ) {
119+ if ( patternMatch ^ patternObject . invert ) {
123120 return value ;
124121 }
125122
126- return this . createError ( ( patternObject . name ? nameRegex : baseRegex ) , { name : patternObject . name , pattern, value } , state , options ) ;
123+ return this . createError ( errorCode , { name : patternObject . name , pattern : patternObject . pattern , value } , state , options ) ;
127124 } ) ;
128125 }
129126
0 commit comments