Skip to content

chore: minor code quality improvements#49

Merged
ruibaby merged 1 commit intohalo-dev:mainfrom
ruibaby:chore/misc-quality-fixes
Apr 27, 2026
Merged

chore: minor code quality improvements#49
ruibaby merged 1 commit intohalo-dev:mainfrom
ruibaby:chore/misc-quality-fixes

Conversation

@ruibaby
Copy link
Copy Markdown
Member

@ruibaby ruibaby commented Apr 27, 2026

Summary

Three small independent improvements:

  • UrlUtils.escapeSitemapUrl(): Replace all five replaceAll() calls with replace(). replaceAll() compiles a regex pattern on every invocation even for literal strings; replace() does a plain string search and is both faster and clearer in intent.

  • SitemapPluginConfig — Content-Type charset: The sitemap response Content-Type was text/xml with no charset declaration. Per RFC 7303, XML served as text/* should declare the encoding explicitly. Changed to text/xml;charset=UTF-8 so clients do not need to guess or rely on the XML declaration inside the document.

  • SitemapPluginConfig — empty sitemap handling: When the lister returns an empty result, the previous code would return HTTP 200 with a blank body. Added .filter(!blank) + .switchIfEmpty(noContent()) so an empty sitemap returns HTTP 204 instead, which is more semantically correct and avoids clients trying to parse an empty body as XML.

Test plan

  • Verify /sitemap.xml response includes Content-Type: text/xml;charset=UTF-8 header
  • On a fresh site with no content, verify /sitemap.xml returns 204 instead of 200 with empty body
  • Confirm existing sitemap generation is unaffected

Made with Cursor

None

@f2c-ci-robot f2c-ci-robot Bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Apr 27, 2026
@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 27, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ruibaby for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot Bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 27, 2026
- Replace String.replaceAll() with String.replace() in UrlUtils.escapeSitemapUrl()
  for literal string substitutions; replaceAll() compiles a regex pattern on every
  call which is unnecessary overhead for plain string replacement
- Set Content-Type to text/xml;charset=UTF-8 in the sitemap endpoint to make
  the charset explicit instead of relying on client-side inference
- Return HTTP 204 No Content when the sitemap is empty rather than serving an
  empty body with 200 OK

Made-with: Cursor
@ruibaby ruibaby force-pushed the chore/misc-quality-fixes branch from bedcc55 to ad2b9b9 Compare April 27, 2026 08:55
@f2c-ci-robot f2c-ci-robot Bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 27, 2026
@ruibaby ruibaby merged commit 32bd2c5 into halo-dev:main Apr 27, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant