@@ -509,6 +509,83 @@ describe("validation plugin - semantic - schema", function() {
509509 }
510510 }
511511
512+ return expectNoErrorsOrWarnings ( spec )
513+ } )
514+ } )
515+ describe ( "'pattern' Z anchors" , function ( ) {
516+ it ( "should return an error when a schema has a Z anchor in its pattern" , ( ) => {
517+
518+ // Given
519+ const spec = {
520+ paths : {
521+ $ref : "#/definitions/asdf"
522+ } ,
523+ "definitions" : {
524+ "asdf" : {
525+ type : "string" ,
526+ pattern : "^[-a-zA-Z0-9_]+\\Z"
527+ }
528+ }
529+ }
530+
531+ // When
532+ return validateHelper ( spec )
533+ . then ( system => {
534+
535+ // Then
536+ expect ( system . errSelectors . allErrors ( ) . count ( ) ) . toEqual ( 1 )
537+ const firstError = system . errSelectors . allErrors ( ) . first ( ) . toJS ( )
538+ expect ( firstError . message ) . toEqual ( `"\\Z" anchors are not allowed in regular expression patterns` )
539+ expect ( firstError . path ) . toEqual ( [ "definitions" , "asdf" , "pattern" ] )
540+ } )
541+
542+ } )
543+ it ( "should return an error when a subschema has a Z anchor in its pattern" , ( ) => {
544+
545+ // Given
546+ const spec = {
547+ paths : {
548+ $ref : "#/definitions/asdf"
549+ } ,
550+ "definitions" : {
551+ "asdf" : {
552+ type : "object" ,
553+ properties : {
554+ slug : {
555+ type : "string" ,
556+ pattern : "^[-a-zA-Z0-9_]+\\Z"
557+ }
558+ }
559+ }
560+ }
561+ }
562+
563+ // When
564+ return validateHelper ( spec )
565+ . then ( system => {
566+
567+ // Then
568+ expect ( system . errSelectors . allErrors ( ) . count ( ) ) . toEqual ( 1 )
569+ const firstError = system . errSelectors . allErrors ( ) . first ( ) . toJS ( )
570+ expect ( firstError . message ) . toEqual ( `"\\Z" anchors are not allowed in regular expression patterns` )
571+ expect ( firstError . path ) . toEqual ( [ "definitions" , "asdf" , "properties" , "slug" , "pattern" ] )
572+ } )
573+
574+ } )
575+
576+ it ( "should not return an error when a regex pattern doesn't use a Z anchor" , ( ) => {
577+ const spec = {
578+ paths : {
579+ $ref : "#/definitions/asdf"
580+ } ,
581+ "definitions" : {
582+ "asdf" : {
583+ type : "string" ,
584+ pattern : "^[-a-zA-Z0-9_]+"
585+ }
586+ }
587+ }
588+
512589 return expectNoErrorsOrWarnings ( spec )
513590 } )
514591 } )
0 commit comments