Skip to content

refactor(transformer): replace URI with URL in HtmlTransformer#148

Merged
marevol merged 1 commit intomasterfrom
refactor/use-url-instead-of-uri-in-html-transformer
Mar 11, 2026
Merged

refactor(transformer): replace URI with URL in HtmlTransformer#148
marevol merged 1 commit intomasterfrom
refactor/use-url-instead-of-uri-in-html-transformer

Conversation

@marevol
Copy link
Contributor

@marevol marevol commented Mar 11, 2026

Summary

Replace java.net.URI with java.net.URL throughout HtmlTransformer to simplify URL resolution logic and remove now-redundant code.

Changes Made

  • Replace URI-based URL resolution with URL-based resolution in storeData()
  • Remove the deprecated getUrlFromTagAttribute(URL, ...) and addChildUrlFromTagAttribute(URL, ...) overloads that delegated to their URI counterparts
  • Remove the complex fallback block in addChildUrlFromTagAttribute that manually reconstructed absolute URLs when URISyntaxException was thrown
  • Handle /../-prefixed paths directly after URL resolution, which is the only edge case URL doesn't normalize automatically
  • Swap URISyntaxException catch for MalformedURLException — cleaner and more precise

Testing

  • Existing test suite covers URL resolution scenarios
  • The removed fallback code handled the same cases that URL.resolve() now handles natively

Breaking Changes

  • The protected getUrlFromTagAttribute(URI, ...) and addChildUrlFromTagAttribute(URI, ...) methods are removed. Any subclasses overriding those methods will need to migrate to the URL-based signatures.

Additional Notes

The previous implementation used URI as the primary type but kept URL wrappers marked @Deprecated, then added a large manual fallback when URISyntaxException was thrown. Since java.net.URL resolves relative references natively and the only gap (/../ normalization) is a small explicit check, the URI path is no longer needed.

Replace java.net.URI with java.net.URL throughout HtmlTransformer to
simplify URL resolution logic. Remove deprecated URI-based overloads and
eliminate the complex fallback path that manually reconstructed absolute
URLs when URISyntaxException was thrown. The URL class handles relative
URL resolution natively, making the code cleaner and more straightforward.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@marevol marevol merged commit cddce2b into master Mar 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant