4 Commits

Author SHA1 Message Date
Timothy DeHerrera
c8ddfb444a refactor: remove test redundancy, reduce API surface
- Remove duplicate xml_escape tests from sitemap.rs and feed.rs
  (already tested in escape.rs)
- Make html_escape_into private (only used internally)
2026-02-06 00:33:10 -07:00
Timothy DeHerrera
8df8aa434f fix(render): fix code block rendering and quote escaping
Two issues fixed:

1. Language-less code blocks (``` without lang) were not accumulating
   text content. The guard `code_block_lang.is_some()` was false for
   them, so content fell through to regular text rendering.

   Fix: Add `in_code_block` flag to track code block state separately
   from language presence.

2. Single quotes in code blocks were being HTML-escaped as ',
   breaking CSP headers like 'self' in documentation.

   Fix: Create code_escape/code_escape_into in escape.rs that only
   escapes <, >, & (required to prevent HTML tag injection) but
   preserves quotes (safe inside <pre><code> content).

Rationale for code_escape:
- < and > MUST be escaped to prevent browser interpreting code as HTML
- & MUST be escaped to prevent HTML entity interpretation
- Quotes are safe inside element content (no attribute context)

Also:
- Add test for unlabeled code block quote preservation

All 71 tests pass.
2026-02-05 17:26:17 -07:00
Timothy DeHerrera
e4a6305a50 fix(escape): add single-quote escaping to html_escape
Add '\'' → '&#39;' case to html_escape_into for complete XSS
protection in HTML attribute contexts. Update documentation
and add test case.

Addresses LOW severity finding from security audit.
2026-02-05 17:07:54 -07:00
Timothy DeHerrera
16f04eb95b refactor: consolidate escape functions and extract weight constants
- Create escape.rs with shared html_escape, html_escape_into, xml_escape
- Remove duplicate implementations from render.rs, highlight.rs, feed.rs, sitemap.rs
- Add DEFAULT_WEIGHT (50) and DEFAULT_WEIGHT_HIGH (99) constants to content.rs
- Replace all magic number weight defaults with named constants

No functional changes; all 67 tests pass.
2026-02-05 14:35:24 -07:00