Skip to content

fix: trim whitespace from domain names before saving hosts#5742

Open
addielaruee wants to merge 1 commit into
NginxProxyManager:developfrom
addielaruee:fix/trim-whitespace-domain-names
Open

fix: trim whitespace from domain names before saving hosts#5742
addielaruee wants to merge 1 commit into
NginxProxyManager:developfrom
addielaruee:fix/trim-whitespace-domain-names

Conversation

@addielaruee

Copy link
Copy Markdown

Why

Fixes #5654.

When a domain/host is entered with a leading or trailing space (easy to do via copy‑paste), NPM stores the space verbatim. The generated nginx config then contains an invalid server_name/upstream, so the host saves but never loads — the user sees a misleading 502 that looks like an upstream problem rather than bad input.

Fix

The proxy_host, dead_host and redirection_host models each sorted domain_names in their $beforeInsert/$beforeUpdate hooks but never trimmed them, and certificate.js carried its own near‑identical (also untrimmed) cleanDomainNames.

This adds a single shared cleanDomainNames helper in backend/lib/helpers.js that:

  • drops null/undefined entries,
  • trims surrounding whitespace,
  • removes any entry left empty after trimming,
  • sorts,

and uses it across all four models, replacing the ad‑hoc per‑model .sort() and removing the duplicated copy in certificate.js. Trimming now applies consistently to every host type (and certificates) at the persistence layer.

Behaviour is a superset of the previous logic (which already filtered null and sorted), so existing well‑formed input is unaffected.

Verification

  • biome lint passes on all five changed files.

  • Unit-style checks of the helper:

    Input Output
    [" example.com ", "b.com"] ["b.com", "example.com"]
    [" spaced.test "] ["spaced.test"]
    ["z.com", "a.com", ""] ["a.com", "z.com"]
    ["keep.com", null, " ", " x.io"] ["keep.com", "x.io"]
    undefined []

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • API changes
  • Performance improvement
  • Test addition or update

AI Usage

  • AI was used to write this
  • AI was used to review this

Entering a proxy/redirection/dead host domain (or a certificate domain) with
a leading or trailing space stored the space verbatim. The generated nginx
server_name/upstream was then invalid, so the host saved but failed to load,
surfacing as a misleading 502 that looks unrelated to the input.

Add a shared cleanDomainNames helper that drops null/empty entries, trims
surrounding whitespace, and sorts, and use it in the proxy_host, dead_host,
redirection_host and certificate models in place of the ad-hoc per-model
sort. The certificate model previously carried its own untrimmed copy of
this logic, which is now removed in favour of the shared helper.

Fixes NginxProxyManager#5654
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.

Remove spaces from domain input

1 participant