Skip to content

Commit c7a71fc

Browse files
willswireclaude
andauthored
fix: trim whitespace from query parameters to prevent cryptic errors (#208)
Leading/trailing spaces in the workers.dev URL (common when copy-pasting from Cloudflare) caused UniFi to show unhelpful error messages. Trimming input parameters handles this gracefully. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d7f1fd3 commit c7a71fc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ function constructClientOptions(request: Request): ClientOptions {
3535
function constructDNSRecords(request: Request): AddressableRecord[] {
3636
const url = new URL(request.url);
3737
const params = url.searchParams;
38-
let ip = params.get('ip') || params.get('myip');
39-
const ip6 = params.get('ip6');
40-
const hostname = params.get('hostname');
38+
let ip = (params.get('ip') || params.get('myip'))?.trim() || null;
39+
const ip6 = params.get('ip6')?.trim() || null;
40+
const hostname = params.get('hostname')?.trim() || null;
4141

4242
if (ip === null || ip === undefined) {
4343
throw new HttpError(422, 'The "ip" parameter is required and cannot be empty. Specify ip=auto to use the client IP.');

0 commit comments

Comments
 (0)