Skip to content

Conversation

@chadbrokaw
Copy link
Collaborator

This pull request enhances the handling of event URLs in the EventCalendar component to ensure all event links have a proper protocol, improving link reliability and user experience. The main focus is on standardizing URLs by automatically adding https:// where needed.

URL handling improvements:

  • Added a helper function ensureHttpsProtocol in EventCalendar.tsx to prepend https:// to event URLs that are missing a protocol, ensuring all external links are valid and clickable.

  • Updated the assignment of the pageLink property for both single and recurring events to use the new ensureHttpsProtocol helper, standardizing URL formatting throughout the calendar. [1] [2]### 📝 Description

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances URL handling in the EventCalendar component by ensuring all event URLs have a proper protocol (https://) for improved link reliability. The change addresses cases where event URLs might be missing the protocol, which could result in broken or non-functional links.

  • Added a utility function ensureHttpsProtocol to automatically prepend https:// to URLs missing a protocol
  • Updated both single and recurring event handling to use the new URL standardization function

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return `https://${trimmedUrl}`;
}

// For other cases (like relative paths), assume https://
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

This fallback logic incorrectly prepends https:// to relative paths, which will break them. Relative paths like /events/123 should be returned as-is, not converted to https:///events/123. Consider returning the original URL unchanged for relative paths or paths that don't match the domain pattern.

Suggested change
// For other cases (like relative paths), assume https://
// For other cases (like relative paths), return as-is if it's a relative path
if (trimmedUrl.startsWith("/")) {
return trimmedUrl;
}
// Otherwise, prepend https://

Copilot uses AI. Check for mistakes.
Comment on lines 117 to 126
// If it starts with www. or looks like a domain, add https://
if (
trimmedUrl.startsWith("www.") ||
/^[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z]{2,}/.test(trimmedUrl)
) {
return `https://${trimmedUrl}`;
}

// For other cases (like relative paths), assume https://
return `https://${trimmedUrl}`;
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

The domain validation regex is overly simplistic and may not handle all valid domain cases (e.g., domains with multiple subdomains, internationalized domains, or ports). Consider using a more robust URL validation approach or a well-tested URL parsing library.

Suggested change
// If it starts with www. or looks like a domain, add https://
if (
trimmedUrl.startsWith("www.") ||
/^[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z]{2,}/.test(trimmedUrl)
) {
return `https://${trimmedUrl}`;
}
// For other cases (like relative paths), assume https://
return `https://${trimmedUrl}`;
// Try to parse as a valid URL; if it fails, prepend https:// and try again
try {
// Try parsing as is (may throw if missing protocol)
new URL(trimmedUrl);
// If no error, but no protocol, add https://
return `https://${trimmedUrl}`;
} catch {
try {
// Try parsing with https:// prepended
new URL(`https://${trimmedUrl}`);
return `https://${trimmedUrl}`;
} catch {
// If still invalid, return original
return trimmedUrl;
}
}

Copilot uses AI. Check for mistakes.
@chadbrokaw chadbrokaw merged commit 8d6bac8 into main Sep 20, 2025
2 checks passed
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