@@ -23,12 +23,12 @@ describe('PackageURL.fromJSON security features', () => {
2323 } )
2424
2525 it ( 'should throw error for JSON exceeding 1MB limit' , ( ) => {
26- // Create a large JSON string that exceeds 1MB
26+ // Create a large JSON string that exceeds 1MB.
2727 const largeQualifiers : Record < string , string > = { }
2828 const qualifierKey = 'q'
2929 const qualifierValue = 'x' . repeat ( 1000 )
3030
31- // Add enough qualifiers to exceed 1MB
31+ // Add enough qualifiers to exceed 1MB.
3232 for ( let i = 0 ; i < 1100 ; i ++ ) {
3333 largeQualifiers [ `${ qualifierKey } ${ i } ` ] = qualifierValue
3434 }
@@ -45,28 +45,30 @@ describe('PackageURL.fromJSON security features', () => {
4545 } )
4646
4747 it ( 'should handle JSON exactly at 1MB limit' , ( ) => {
48- // Create a JSON string that's exactly 1MB
48+ // Create a JSON string that's exactly 1MB.
4949 const targetSize = 1024 * 1024
5050 const baseJson = { type : 'npm' , name : 'test' , namespace : '' }
5151 const baseSize = JSON . stringify ( baseJson ) . length
52- const paddingSize = targetSize - baseSize - 2 // Account for quotes
52+ // Account for quotes.
53+ const paddingSize = targetSize - baseSize - 2
5354
5455 if ( paddingSize > 0 ) {
5556 baseJson . namespace = 'x' . repeat ( paddingSize )
5657 const exactJson = JSON . stringify ( baseJson )
5758
58- // Should work at exactly the limit
59+ // Should work at exactly the limit.
5960 const result = PackageURL . fromJSON ( exactJson )
6061 expect ( result ) . toBeInstanceOf ( PackageURL )
6162 }
6263 } )
6364
6465 it ( 'should reject JSON just over 1MB limit' , ( ) => {
65- // Create a JSON string that's just over 1MB
66+ // Create a JSON string that's just over 1MB.
6667 const targetSize = 1024 * 1024
6768 const baseJson = { type : 'npm' , name : 'test' , namespace : '' }
6869 const baseSize = JSON . stringify ( baseJson ) . length
69- const paddingSize = targetSize - baseSize - 1 // One byte over
70+ // One byte over.
71+ const paddingSize = targetSize - baseSize - 1
7072
7173 if ( paddingSize > 0 ) {
7274 baseJson . namespace = 'x' . repeat ( paddingSize )
@@ -149,8 +151,8 @@ describe('PackageURL.fromJSON security features', () => {
149151 } ,
150152 } )
151153
152- // Note: This might not be caught depending on implementation depth
153- // But we should at least not crash
154+ // Note: This might not be caught depending on implementation depth,
155+ // but we should at least not crash.
154156 expect ( ( ) => PackageURL . fromJSON ( maliciousJson ) ) . not . toThrow ( TypeError )
155157 } )
156158 } )
@@ -269,7 +271,7 @@ describe('PackageURL.fromJSON security features', () => {
269271 expect ( ( ) => PackageURL . fromJSON ( largeJson ) ) . toThrow ( )
270272
271273 const duration = performance . now ( ) - start
272- // Should fail fast (under 100ms) by checking size before parsing
274+ // Should fail fast (under 100ms) by checking size before parsing.
273275 expect ( duration ) . toBeLessThan ( 100 )
274276 } )
275277
0 commit comments