@@ -27,6 +27,30 @@ describe("Multipart", function () {
2727 expect ( new TextDecoder ( ) . decode ( multipart . boundary ) ) . to . equal ( "empty-boundary" ) ;
2828 expect ( multipart . mediaType ) . to . equal ( "multipart/mixed" ) ;
2929 } ) ;
30+
31+ it ( "should accept only valid boundaries" , function ( ) {
32+ expect ( ( ) => new Multipart ( [ ] , "" ) ) . to . throw ( RangeError , "Invalid boundary" ) ;
33+ expect ( ( ) => new Multipart ( [ ] , " " ) ) . to . throw ( RangeError , "Invalid boundary" ) ;
34+ expect ( ( ) => new Multipart ( [ ] , "a " ) ) . to . throw ( RangeError , "Invalid boundary" ) ;
35+ expect ( ( ) => new Multipart ( [ ] , "0123456789" . repeat ( 7 ) + "0" ) ) . to . throw ( RangeError , "Invalid boundary" ) ;
36+ expect ( ( ) => new Multipart ( [ ] , "foo!bar" ) ) . to . throw ( RangeError , "Invalid boundary" ) ;
37+
38+ expect ( ( ) => new Multipart ( [ ] , "a" ) ) . to . not . throw ( ) ;
39+ expect ( ( ) => new Multipart ( [ ] , "0123456789" . repeat ( 7 ) ) ) . to . not . throw ( ) ;
40+ expect ( ( ) => new Multipart ( [ ] , "foo bar" ) ) . to . not . throw ( ) ;
41+ expect ( ( ) => new Multipart ( [ ] , "foo'bar" ) ) . to . not . throw ( ) ;
42+ expect ( ( ) => new Multipart ( [ ] , "foo(bar" ) ) . to . not . throw ( ) ;
43+ expect ( ( ) => new Multipart ( [ ] , "foo)bar" ) ) . to . not . throw ( ) ;
44+ expect ( ( ) => new Multipart ( [ ] , "foo+bar" ) ) . to . not . throw ( ) ;
45+ expect ( ( ) => new Multipart ( [ ] , "foo_bar" ) ) . to . not . throw ( ) ;
46+ expect ( ( ) => new Multipart ( [ ] , "foo,bar" ) ) . to . not . throw ( ) ;
47+ expect ( ( ) => new Multipart ( [ ] , "foo-bar" ) ) . to . not . throw ( ) ;
48+ expect ( ( ) => new Multipart ( [ ] , "foo.bar" ) ) . to . not . throw ( ) ;
49+ expect ( ( ) => new Multipart ( [ ] , "foo/bar" ) ) . to . not . throw ( ) ;
50+ expect ( ( ) => new Multipart ( [ ] , "foo:bar" ) ) . to . not . throw ( ) ;
51+ expect ( ( ) => new Multipart ( [ ] , "foo=bar" ) ) . to . not . throw ( ) ;
52+ expect ( ( ) => new Multipart ( [ ] , "foo?bar" ) ) . to . not . throw ( ) ;
53+ } ) ;
3054 } ) ;
3155
3256 describe ( "parse" , function ( ) {
0 commit comments