Skip to content

Commit 5b33708

Browse files
kylehowellsclaude
andcommitted
Fix swiftformat linting issues in DoSProtectionTests
Applied blankLinesBetweenImports, markTypes, and spaceAroundOperators rules. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f2a6a1c commit 5b33708

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

Tests/swift-justhtmlTests/DoSProtectionTests.swift

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
import Foundation
1616
import Testing
17-
1817
@testable import justhtml
1918

20-
// MARK: - Entity Name Length DoS Tests
19+
// MARK: - EntityNameLengthTests
2120

2221
/// Tests for entity name length limits
2322
/// The longest valid HTML entity is ~31 characters (e.g., "CounterClockwiseContourIntegral")
@@ -124,7 +123,7 @@ struct EntityNameLengthTests {
124123
}
125124
}
126125

127-
// MARK: - Nesting Depth DoS Tests
126+
// MARK: - NestingDepthTests
128127

129128
/// Tests for maximum nesting depth limits
130129
/// Real web pages rarely exceed 100-200 levels of nesting
@@ -169,12 +168,12 @@ struct NestingDepthTests {
169168
var html = ""
170169
let depth = 400 // Safe depth
171170

172-
for i in 0..<depth {
171+
for i in 0 ..< depth {
173172
let tag = tags[i % tags.count]
174173
html += "<\(tag)>"
175174
}
176175
html += "deep content"
177-
for i in (0..<depth).reversed() {
176+
for i in (0 ..< depth).reversed() {
178177
let tag = tags[i % tags.count]
179178
html += "</\(tag)>"
180179
}
@@ -189,11 +188,11 @@ struct NestingDepthTests {
189188
let depth = 200 // Tables are more complex
190189
var html = ""
191190

192-
for _ in 0..<depth {
191+
for _ in 0 ..< depth {
193192
html += "<table><tr><td>"
194193
}
195194
html += "cell"
196-
for _ in 0..<depth {
195+
for _ in 0 ..< depth {
197196
html += "</td></tr></table>"
198197
}
199198

@@ -241,11 +240,11 @@ struct NestingDepthTests {
241240
@Test func testDeepSVGNesting() throws {
242241
let depth = 300
243242
var html = "<svg>"
244-
for _ in 0..<depth {
243+
for _ in 0 ..< depth {
245244
html += "<g>"
246245
}
247246
html += "<text>deep</text>"
248-
for _ in 0..<depth {
247+
for _ in 0 ..< depth {
249248
html += "</g>"
250249
}
251250
html += "</svg>"
@@ -259,11 +258,11 @@ struct NestingDepthTests {
259258
@Test func testDeepMathMLNesting() throws {
260259
let depth = 300
261260
var html = "<math>"
262-
for _ in 0..<depth {
261+
for _ in 0 ..< depth {
263262
html += "<mrow>"
264263
}
265264
html += "<mi>x</mi>"
266-
for _ in 0..<depth {
265+
for _ in 0 ..< depth {
267266
html += "</mrow>"
268267
}
269268
html += "</math>"
@@ -318,7 +317,7 @@ struct NestingDepthTests {
318317
}
319318
}
320319

321-
// MARK: - Adoption Agency DoS Tests
320+
// MARK: - AdoptionAgencyTests
322321

323322
/// Tests for adoption agency algorithm limits
324323
/// The adoption agency is O(n²) in worst case - we need limits
@@ -328,12 +327,12 @@ struct AdoptionAgencyTests {
328327
@Test func testManyOverlappingFormatting() throws {
329328
let count = 200
330329
var html = ""
331-
for i in 0..<count {
330+
for i in 0 ..< count {
332331
html += "<b id=\"\(i)\">"
333332
}
334333
html += "text"
335334
// Close in wrong order to trigger adoption agency
336-
for i in 0..<count {
335+
for i in 0 ..< count {
337336
html += "</b>"
338337
if i % 10 == 0 {
339338
html += "<p>para</p>" // Block elements interspersed
@@ -348,11 +347,11 @@ struct AdoptionAgencyTests {
348347
/// Test adoption agency with nested blocks (within safe limits)
349348
@Test func testAdoptionAgencyDeepBlocks() throws {
350349
var html = ""
351-
for _ in 0..<100 {
350+
for _ in 0 ..< 100 {
352351
html += "<b><div>"
353352
}
354353
html += "content"
355-
for _ in 0..<100 {
354+
for _ in 0 ..< 100 {
356355
html += "</b></div>"
357356
}
358357

@@ -373,7 +372,7 @@ struct AdoptionAgencyTests {
373372
}
374373
}
375374

376-
// MARK: - Active Formatting Elements DoS Tests
375+
// MARK: - ActiveFormattingTests
377376

378377
/// Tests for active formatting elements list limits
379378
@Suite("Active Formatting Elements DoS Protection")
@@ -383,7 +382,7 @@ struct ActiveFormattingTests {
383382
var html = ""
384383
let tags = ["a", "b", "code", "em", "i", "s", "small", "strong", "u"]
385384

386-
for i in 0..<200 {
385+
for i in 0 ..< 200 {
387386
let tag = tags[i % tags.count]
388387
html += "<\(tag) class=\"c\(i)\">"
389388
}
@@ -397,11 +396,11 @@ struct ActiveFormattingTests {
397396
/// Test formatting elements with many markers (table cells)
398397
@Test func testFormattingWithManyMarkers() throws {
399398
var html = "<table>"
400-
for _ in 0..<100 {
399+
for _ in 0 ..< 100 {
401400
html += "<tr><td><b><i>"
402401
}
403402
html += "cell"
404-
for _ in 0..<100 {
403+
for _ in 0 ..< 100 {
405404
html += "</i></b></td></tr>"
406405
}
407406
html += "</table>"
@@ -412,7 +411,7 @@ struct ActiveFormattingTests {
412411
}
413412
}
414413

415-
// MARK: - Combined DoS Tests
414+
// MARK: - CombinedDoSTests
416415

417416
/// Tests combining multiple DoS vectors
418417
@Suite("Combined DoS Protection")
@@ -424,11 +423,11 @@ struct CombinedDoSTests {
424423
let depth = 200
425424
var html = ""
426425

427-
for _ in 0..<depth {
426+
for _ in 0 ..< depth {
428427
html += "<div>&\(longEntity);"
429428
}
430429
html += "content"
431-
for _ in 0..<depth {
430+
for _ in 0 ..< depth {
432431
html += "</div>"
433432
}
434433

@@ -448,27 +447,27 @@ struct CombinedDoSTests {
448447
var html = ""
449448

450449
// Moderate nesting
451-
for i in 0..<100 {
450+
for i in 0 ..< 100 {
452451
html += "<div class=\"d\(i)\">"
453452
}
454453

455454
// Long entity (should abort quickly with limit)
456455
html += "&\(longEntity);"
457456

458457
// Some formatting elements
459-
for _ in 0..<50 {
458+
for _ in 0 ..< 50 {
460459
html += "<b><i><u>"
461460
}
462461

463462
html += "stress test content"
464463

465464
// Close some formatting
466-
for _ in 0..<25 {
465+
for _ in 0 ..< 25 {
467466
html += "</u></i></b>"
468467
}
469468

470469
// Close divs
471-
for _ in 0..<100 {
470+
for _ in 0 ..< 100 {
472471
html += "</div>"
473472
}
474473

@@ -482,7 +481,7 @@ struct CombinedDoSTests {
482481
var html = "<!DOCTYPE html><html><head><title>Test</title></head><body>"
483482

484483
// Add various patterns
485-
for i in 0..<50 {
484+
for i in 0 ..< 50 {
486485
// Moderate nesting section
487486
let opens = String(repeating: "<div>", count: 10)
488487
let closes = String(repeating: "</div>", count: 10)
@@ -508,7 +507,7 @@ struct CombinedDoSTests {
508507
}
509508
}
510509

511-
// MARK: - Performance Baseline Tests
510+
// MARK: - DoSPerformanceTests
512511

513512
/// Tests to establish performance baselines for DoS protection
514513
@Suite("DoS Protection Performance")

0 commit comments

Comments
 (0)