Releases: kylehowells/swift-justhtml
0.4.1
Bug Fixes
-
Fix attributes losing values when whitespace surrounds
=sign (#2) — HTML like<a href = "http://example.com">was producing an emptyhrefattribute. The tokenizer was prematurely storing the attribute before the value could be read. -
Fix select fragment context producing incorrect trees — Parsing HTML in a
selectfragment context (e.g.<table></table><li><table></table>) was dropping elements and inserting spurious<head>/<body>nodes. The tree builder'sresetInsertionMode()was incorrectly switching toinSelectmode via the virtual context element.
Improvements
- Test infrastructure now includes bundled project-specific
.datfiles — Tree construction tests now discover and run.datfiles from both the external html5lib-tests repo and the bundled test resources, ensuring project-specific regression tests are always included.
Version 0.4.0 - DoS Protection
New Features
ParserLimits - Configurable DoS Protection
swift-justhtml now includes configurable limits to protect against denial-of-service attacks from malicious HTML input:
// Default limits are applied automatically (recommended)
let doc = try JustHTML(untrustedHTML)
// Custom limits for servers with more resources
var limits = ParserLimits()
limits.maxNestingDepth = 2048
let doc = try JustHTML(html, limits: limits)
// Stricter limits for resource-constrained devices
let doc = try JustHTML(html, limits: .strict)
// Disable limits for trusted content only
let doc = try JustHTML(trustedHTML, limits: .unlimited)Limits
| Limit | Default | Description |
|---|---|---|
maxEntityNameLength |
255 | Prevents memory attacks from extremely long invalid entity names (e.g., &aaaa... with millions of characters) |
maxNestingDepth |
512 | Prevents stack overflow from extremely deep DOM nesting (e.g., 10,000+ nested <div> elements) |
Presets
| Preset | Entity Length | Nesting Depth | Use Case |
|---|---|---|---|
.default |
255 | 512 | General use |
.strict |
128 | 256 | Mobile/embedded |
.unlimited |
unlimited | unlimited | Trusted content only |
Test Results
All html5lib tests continue to pass:
| Test Suite | Passed | Failed |
|---|---|---|
| Tree Construction | 1,831 | 0 |
| Tokenizer | 6,810 | 0 |
| Total | 8,641 | 0 |
Documentation
v0.3.3 Bug fixed
- Fixed markdown rendering newlines at the start of
<p>elements. - Fixed flacky speed profiling test
v0.3
Breaking Change
Module renamed from swift_justhtml to justhtml
// Before
import swift_justhtml
// After
import justhtmlUpdate your Package.swift dependency:
dependencies: ["justhtml"]New Features
Example CLI Tools
- html2md - Minimal HTML to Markdown converter demonstrating
toMarkdown()API - extractlinks - Extract all links from HTML using CSS selectors
Documentation
- Added comprehensive DocC documentation with GitHub Pages hosting
- New guides: Performance, Benchmarking, Examples, Getting Started
- Added READMEs for all example tools
- Interactive Xcode Playground with examples
Benchmarking
- Memory usage comparison script (
memory_compare.py) - Synthetic HTML generator for consistent benchmarking
- Updated benchmark scripts to support test files directory
Improvements
API Cleanup
- Made internal constants and types properly internal (not public):
Constants.swiftvariables (VOID_ELEMENTS, ASCII_WHITESPACE, etc.)- Entity lookup tables (LEGACY_ENTITIES, NAMED_ENTITIES)
- Experimental ArenaNode types
- Removed unused experimental ArenaNode code
Platform Support
- Added visionOS support
- Temporarily disabled macOS GitHub Actions runners