Skip to content

Validate subdomain input to prevent a crash - #130

Merged
winebarrel merged 1 commit into
mainfrom
validate-subdomain
Jul 9, 2026
Merged

Validate subdomain input to prevent a crash#130
winebarrel merged 1 commit into
mainfrom
validate-subdomain

Conversation

@winebarrel

Copy link
Copy Markdown
Owner

Problem

Region.webBaseURL(subdomain:) interpolates the user-entered subdomain into a URL string and force-unwraps it:

return URL(string: "https://\(subdomain).pagerduty.com")!

The Subdomain field (SettingsView) is free-form text with no validation. If it contains characters that make URL(string:) return nil — a space, %, :, a newline (easy to paste in accidentally) — the force-unwrap crashes the app the moment the user opens “My Incidents” / “My On-Call Shifts” from the right-click menu.

Verified crashing inputs: "foo bar", " leadingspace", "%", "foo:80", "a\nb".

Fix

Filter the Subdomain field to alphanumerics and hyphens (valid PagerDuty subdomain characters) via .onChange, mirroring the existing clamp on the interval field. Invalid characters are stripped as they are entered, so the constructed URL is always valid.

🤖 Generated with Claude Code

A subdomain containing characters such as spaces, colons, %, or newlines
makes URL(string:) return nil in Region.webBaseURL, which force-unwraps
and crashes the app when opening the right-click menu links. Filter the
Subdomain field to alphanumerics and hyphens so the constructed URL is
always valid.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvQ1BLHNVbshkwL2qTosFa

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents a macOS app crash caused by force-unwrapping URL(string:) after interpolating an unvalidated, user-entered PagerDuty subdomain into a URL.

Changes:

  • Adds live input filtering on the Settings “Subdomain” field to strip characters that can make URL(string:) return nil.
  • Introduces a shared Constants.subdomainAllowedCharacters CharacterSet (ASCII alphanumerics + -) used by the new filter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
PagerCall/SettingsView.swift Filters subdomain text as it changes so the stored value can’t contain URL-breaking characters.
PagerCall/Constants.swift Defines the allowed character set for PagerDuty subdomains and documents why it exists.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@winebarrel
winebarrel merged commit 3d74c2c into main Jul 9, 2026
4 checks passed
@winebarrel
winebarrel deleted the validate-subdomain branch July 9, 2026 14:46
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.

2 participants