@@ -105,6 +105,7 @@ define(function (require, exports, module) {
105105 * - Have a leading dot (if not empty or "all")
106106 * - Are properly separated with commas and spaces
107107 * - Don't contain empty or standalone dots
108+ * - No consecutive commas
108109 *
109110 * @param {string } extension - The file extension(s) to process
110111 * @returns {string } - The properly formatted file extension(s)
@@ -119,25 +120,12 @@ define(function (require, exports, module) {
119120 extension = extension . replace ( / \s + / g, "," ) ;
120121 }
121122
122- // Step 2: handle multiple extensions joined by dots (e.g., ".less.css.js")
123- // Only process if multiple dots exist and not already comma-separated
124- const dotCount = ( extension . match ( / \. / g) || [ ] ) . length ;
125- if ( dotCount > 1 ) {
126- // remove the leading dot if present for consistent processing
127- const extensionWithoutLeadingDot = extension . startsWith ( "." ) ? extension . substring ( 1 ) : extension ;
123+ let result = "" ;
128124
129- // split by dot, filter empty parts, add leading dot to each part
130- const parts = extensionWithoutLeadingDot
131- . split ( "." )
132- . filter ( ( part ) => part !== "" )
133- . map ( ( part ) => "." + part ) ;
134-
135- return parts . join ( ", " ) ;
136- }
137-
138- // Step 3: process comma-separated extensions
125+ // Step 2: process comma-separated extensions FIRST (before dot-separated)
126+ // this prevents issues with inputs like ".js,.html,." or ".js,,.html"
139127 if ( extension . includes ( "," ) ) {
140- return extension
128+ result = extension
141129 . split ( "," )
142130 . map ( ( ext ) => {
143131 ext = ext . trim ( ) ;
@@ -150,15 +138,36 @@ define(function (require, exports, module) {
150138 } )
151139 . filter ( ( ext ) => ext !== "" ) // Remove empty entries
152140 . join ( ", " ) ;
141+ } else {
142+ // Step 3: handle multiple extensions joined by dots (e.g., ".less.css.js")
143+ // Only process if multiple dots exist and no commas
144+ const dotCount = ( extension . match ( / \. / g) || [ ] ) . length ;
145+ if ( dotCount > 1 ) {
146+ // remove the leading dot if present for consistent processing
147+ const extensionWithoutLeadingDot = extension . startsWith ( "." ) ? extension . substring ( 1 ) : extension ;
148+
149+ // split by dot, filter empty parts, add leading dot to each part
150+ const parts = extensionWithoutLeadingDot
151+ . split ( "." )
152+ . filter ( ( part ) => part !== "" )
153+ . map ( ( part ) => "." + part ) ;
154+
155+ result = parts . join ( ", " ) ;
156+ } else {
157+ // Step 4: Handle single extension
158+ if ( extension === "." ) {
159+ result = "" ; // remove standalone dot
160+ } else {
161+ // Add leading dot if missing
162+ result = extension . startsWith ( "." ) ? extension : "." + extension ;
163+ }
164+ }
153165 }
154166
155- // Step 4: Handle single extension
156- if ( extension === "." ) {
157- return "" ; // remove standalone dot
158- }
167+ // this is just the final safeguard to remove any consecutive commas and clean up spacing
168+ result = result . replace ( / , \s * , + / g, "," ) . replace ( / , \s * $ / , "" ) . replace ( / ^ \s * , / , "" ) . trim ( ) ;
159169
160- // Add leading dot if missing
161- return extension . startsWith ( "." ) ? extension : "." + extension ;
170+ return result ;
162171 }
163172
164173 /**
0 commit comments