fix: trim whitespace from domain names before saving hosts - #5742
addielaruee wants to merge 1 commit into
Conversation
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
|
Docker Image for build 2 is available on DockerHub: Note Ensure you backup your NPM instance before testing this image! Especially if there are database changes. Warning Changes and additions to DNS Providers require verification by at least 2 members of the community! |
|
Thanks for taking the time to fix this. I found 2 issues. Both come from the trimming being done too late: it happens in the model save hooks, after the duplicate-host check and schema validation have already run on the untrimmed names.
The regex pattern for |
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 misleading502that looks like an upstream problem rather than bad input.Fix
The
proxy_host,dead_hostandredirection_hostmodels each sorteddomain_namesin their$beforeInsert/$beforeUpdatehooks but never trimmed them, andcertificate.jscarried its own near‑identical (also untrimmed)cleanDomainNames.This adds a single shared
cleanDomainNameshelper inbackend/lib/helpers.jsthat:null/undefinedentries,and uses it across all four models, replacing the ad‑hoc per‑model
.sort()and removing the duplicated copy incertificate.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
nulland sorted), so existing well‑formed input is unaffected.Verification
biome lintpasses on all five changed files.Unit-style checks of the helper:
[" 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
AI Usage