Skip to content

Normalize links in HTML subset formatting - #190

Merged
snoopdave merged 1 commit into
masterfrom
codex/html-subset-links
Sep 17, 2026
Merged

snoopdave merged 1 commit into
masterfrom
codex/html-subset-links

Conversation

@snoopdave

Copy link
Copy Markdown
Contributor

Normalize supported links to a consistent href format while preserving comment text and basic formatting.

Adds coverage for quoted and unquoted links, query strings, whitespace, entity text, and plain-text comments.

Validation: mvn -V -ntp install on JDK 25 — 307 tests, no failures or errors, one skipped.

@snoopdave snoopdave left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR-Review: 3 inline comments posted.

Comment thread app/src/main/java/org/apache/roller/weblogger/util/Utilities.java
Comment thread app/src/main/java/org/apache/roller/weblogger/util/Utilities.java

// HTTP links
// Normalize supported links while retaining the surrounding text.
s = replace(s, CLOSING_A_TAG_PATTERN, "</a>");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞Claude Issue: Important: CLOSING_A_TAG_PATTERN rewrites &lt;/a&gt; unconditionally, but the opening tag is only rewritten when OPENING_A_TAG_PATTERN matches. Anchors it does not recognise therefore emit an unbalanced </a>:

<a>x</a>                              ->  &lt;a&gt;x</a>
<a class="c" href="https://x/">y</a>  ->  &lt;a class="c" href="https://x/"&gt;y</a>

This is pre-existing, but the loop is being rewritten here and already has an "unsupported anchor" output (<a>). Emitting that for unmatched opening tags as well would keep the markup balanced for a couple of lines of change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖Claude: fixed by broadening OPENING_A_TAG_PATTERN to &lt;a(?:\s[\s\S]*?)?&gt; so it matches every escaped opening anchor, not just ones starting <a href=. Each one now goes through the same reconstruction, so an anchor whose href is missing or unusable becomes <a> and the markup stays balanced:

<a>x</a>                              ->  <a>x</a>
<a name="anchor">x</a>                ->  <a>x</a>
<a class="c" href="https://x/">y</a>  ->  <a href="https://x/">y</a>

The pattern requires whitespace or the closing delimiter after a, so sibling tags are unaffected — <abbr> still passes through escaped. Covered by new test testHtmlSubsetBalancesUnsupportedAnchors.

@snoopdave

Copy link
Copy Markdown
Contributor Author

🐞Claude Issue: PR-Review: General Issues

The following issues were found but cannot be attached to a specific line in the diff:

  • Blocking: CHANGES.md is not updated. The repo keeps its changelog there and the ## 6.1.6 section is open, with "Behaviour changes worth reading before upgrading" and "Improvements" subsections. This PR changes how every HTML comment renders — anchors are now reconstructed from a validated href instead of passed through, and anchors that are not recognised lose their href — which is user-visible behaviour of exactly the kind that section documents. Please add a short entry (a sentence plus a couple of bullets), with a link to the associated GitHub issue if there is one.

  • Important: Public API documentation does not reflect the narrowed contract. transformToHTMLSubset is exposed to templates as $utils.transformToHTMLSubset (UtilitiesModel.java:346) and is documented in docs/roller-template-guide.adoc:881 as "Transform any HTML in the string to a safe HTML subset". After this change, anchor href values are limited to http, https and mailto, and every other anchor attribute is dropped. Neither the template guide nor the method javadoc (Utilities.java:949-957, which still describes support for <a href> without qualification) mentions either restriction. Both are outside the diff hunks, hence this general comment.

@snoopdave

Copy link
Copy Markdown
Contributor Author

🤖Claude: fixed both.

Changelog — added a bullet to the ## 6.1.6 "Improvements" section of CHANGES.md naming the three visible changes to HTML comment rendering: the scheme restriction, the dropping of non-href attributes, and anchors no longer leaving an unbalanced closing tag. No GitHub issue is referenced because this PR does not have an associated one.

Docs — updated both places:

  • docs/roller-template-guide.adoc now states that $utils.transformToHTMLSubset expects already-escaped input (raw HTML passes through untouched), that anchors are rebuilt with a single href and no other attributes, and that only http, https and mailto are kept.
  • The javadoc on Utilities.transformToHTMLSubset carries the same three points, so callers see the contract without going to the guide.

@snoopdave
snoopdave merged commit aa03eaa into master Sep 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant