Skip to content

Releases: kylehowells/swift-justhtml

0.4.1

24 Mar 22:28

Choose a tag to compare

Bug Fixes

  • Fix attributes losing values when whitespace surrounds = sign (#2) — HTML like <a href = "http://example.com"> was producing an empty href attribute. The tokenizer was prematurely storing the attribute before the value could be read.

  • Fix select fragment context producing incorrect trees — Parsing HTML in a select fragment context (e.g. <table></table><li><table></table>) was dropping elements and inserting spurious <head>/<body> nodes. The tree builder's resetInsertionMode() was incorrectly switching to inSelect mode via the virtual context element.

Improvements

  • Test infrastructure now includes bundled project-specific .dat files — Tree construction tests now discover and run .dat files 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

24 Mar 22:13

Choose a tag to compare

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

18 Dec 09:25

Choose a tag to compare

  • Fixed markdown rendering newlines at the start of <p> elements.
  • Fixed flacky speed profiling test

v0.3

17 Dec 23:52

Choose a tag to compare

Breaking Change

Module renamed from swift_justhtml to justhtml

// Before
import swift_justhtml

// After
import justhtml

Update 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.swift variables (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

Full Changelog

v0.2...v0.3