@@ -30,6 +30,7 @@ import {
30
30
createSyntheticResult ,
31
31
getGenericSyntheticResult ,
32
32
LinkIntermediate ,
33
+ sanitizeObjectName ,
33
34
shuffleAndTruncate ,
34
35
} from '../../src/link_utils' ;
35
36
import { setDefaultOptions } from '../../src/options_func' ;
@@ -210,4 +211,34 @@ describe('GCM Synthetics Broken Links Utilies', async () => {
210
211
expect ( startTime ) . to . be . lessThan ( endTime ) ;
211
212
expect ( milliDifference ) . to . be . greaterThan ( 0 ) ;
212
213
} ) ;
214
+
215
+ describe ( 'sanitizeObjectName' , ( ) => {
216
+ it ( 'should remove invalid characters' , ( ) => {
217
+ const input = "test/\@#$%^&*()/_+\-=[]{};':\"\|,.<>/?\r\n\t" ;
218
+ const expectedOutput = "test_@_$%^&_()__+-=__{};'__\_,.______" ;
219
+ expect ( sanitizeObjectName ( input ) ) . to . equal ( expectedOutput ) ;
220
+ } ) ;
221
+
222
+ it ( 'should replace the forbidden prefix' , ( ) => {
223
+ const input = ".well-known/acme-challenge/test" ;
224
+ const expectedOutput = "_test" ;
225
+ expect ( sanitizeObjectName ( input ) ) . to . equal ( expectedOutput ) ;
226
+ } ) ;
227
+
228
+ it ( 'should handle standalone "." and ".."' , ( ) => {
229
+ expect ( sanitizeObjectName ( "." ) ) . to . equal ( "_" ) ;
230
+ expect ( sanitizeObjectName ( ".." ) ) . to . equal ( "_" ) ;
231
+ } ) ;
232
+
233
+ it ( 'should handle null and undefined' , ( ) => {
234
+ expect ( sanitizeObjectName ( null ) ) . to . equal ( "_" ) ;
235
+ expect ( sanitizeObjectName ( undefined ) ) . to . equal ( "_" ) ;
236
+ } )
237
+
238
+ it ( 'should trim leading and trailing whitespace' , ( ) => {
239
+ const input = " test name " ;
240
+ const expectedOutput = "test_name" ;
241
+ expect ( sanitizeObjectName ( input ) ) . to . equal ( expectedOutput ) ;
242
+ } ) ;
243
+ } ) ;
213
244
} ) ;
0 commit comments