fix: trim whitespace from domain names before saving hosts#5742
Open
addielaruee wants to merge 1 commit into
Open
fix: trim whitespace from domain names before saving hosts#5742addielaruee wants to merge 1 commit into
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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