@@ -95,6 +95,40 @@ describe("parseAllowedFormats", () => {
9595 "Value 'application-pdf' is not recognized. Accepted format: 'image/jpeg'"
9696 ) ;
9797 } ) ;
98+ test ( "handles extensions with special characters like dashes and plus signs" , ( ) => {
99+ const input : AllowedFileFormatsType [ ] = [
100+ {
101+ configMode : "advanced" ,
102+ typeFormatDescription : dynamicValue ( "special-extensions" ) ,
103+ predefinedType : "pdfFile" ,
104+ mimeType : "application/x-custom" ,
105+ extensions : ".tar-gz,.js-map,.c++"
106+ }
107+ ] ;
108+
109+ expect ( parseAllowedFormats ( input ) ) . toEqual ( [
110+ {
111+ description : "special-extensions" ,
112+ entries : [ [ "application/x-custom" , [ ".tar-gz" , ".js-map" , ".c++" ] ] ]
113+ }
114+ ] ) ;
115+ } ) ;
116+ test ( "throws on extension without leading dot" , ( ) => {
117+ const input : AllowedFileFormatsType [ ] = [
118+ {
119+ configMode : "advanced" ,
120+ typeFormatDescription : dynamicValue ( "test" ) ,
121+ predefinedType : "pdfFile" ,
122+ mimeType : "text/*" ,
123+ extensions : ".txt,pdf"
124+ }
125+ ] ;
126+
127+ expect ( ( ) => parseAllowedFormats ( input ) ) . toThrow (
128+ "Value 'pdf' is not recognized. Extension must start with a dot and contain only valid filename characters"
129+ ) ;
130+ } ) ;
131+
98132 test ( "throws on incorrect extension format" , ( ) => {
99133 const input : AllowedFileFormatsType [ ] = [
100134 {
@@ -106,6 +140,24 @@ describe("parseAllowedFormats", () => {
106140 }
107141 ] ;
108142
109- expect ( ( ) => parseAllowedFormats ( input ) ) . toThrow ( "Value 'abc' is not recognized. Accepted format: '.pdf'" ) ;
143+ expect ( ( ) => parseAllowedFormats ( input ) ) . toThrow (
144+ "Value 'abc' is not recognized. Extension must start with a dot and contain only valid filename characters"
145+ ) ;
146+ } ) ;
147+
148+ test ( "throws on extension with dot in the middle" , ( ) => {
149+ const input : AllowedFileFormatsType [ ] = [
150+ {
151+ configMode : "advanced" ,
152+ typeFormatDescription : dynamicValue ( "test" ) ,
153+ predefinedType : "pdfFile" ,
154+ mimeType : "text/*" ,
155+ extensions : ".txt,.config.json"
156+ }
157+ ] ;
158+
159+ expect ( ( ) => parseAllowedFormats ( input ) ) . toThrow (
160+ "Value '.config.json' is not recognized. Extension must start with a dot and contain only valid filename characters"
161+ ) ;
110162 } ) ;
111163} ) ;
0 commit comments