-
Notifications
You must be signed in to change notification settings - Fork 2.8k
sanitize social media handles for the partners #2585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe changes introduce a new utility for sanitizing social media handles, apply this sanitization in the partner online presence update schema, refactor form paste handling to use the sanitizer, and add a script to retroactively clean existing database records. The sanitizer standardizes handle formats across five social platforms. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant OnlinePresenceForm
participant sanitizeSocialHandle
participant FormState
User->>OnlinePresenceForm: Paste social handle
OnlinePresenceForm->>sanitizeSocialHandle: Sanitize pasted input (with platform)
sanitizeSocialHandle-->>OnlinePresenceForm: Return sanitized handle
OnlinePresenceForm->>FormState: Update field value with sanitized handle
sequenceDiagram
participant Script
participant Database
participant sanitizeSocialHandle
Script->>Database: Query partners with social handles
loop For each partner and handle
Script->>sanitizeSocialHandle: Sanitize handle (with platform)
end
Script->>Database: Update partner records with sanitized handles
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
apps/web/scripts/sanitize-social-handles.ts (1)
49-58: Optimize sanitization trigger condition.The current condition
value.startsWith("http") || value.startsWith("@")may miss handles that need sanitization but don't start with these prefixes (e.g., handles with disallowed characters or incorrect casing).Consider sanitizing all handles and comparing the result to the original:
- for (const [platform, value] of Object.entries(socialHandles)) { - if (value && (value.startsWith("http") || value.startsWith("@"))) { - updatedSocialHandles[platform] = sanitizeSocialHandle( - value, - platform as SocialPlatform, - ); - - needsUpdate = true; - } - } + for (const [platform, value] of Object.entries(socialHandles)) { + if (value) { + const sanitized = sanitizeSocialHandle( + value, + platform as SocialPlatform, + ); + + if (sanitized !== value) { + updatedSocialHandles[platform] = sanitized; + needsUpdate = true; + } + } + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/web/lib/actions/partners/update-online-presence.ts(2 hunks)apps/web/lib/social-utils.ts(1 hunks)apps/web/scripts/sanitize-social-handles.ts(1 hunks)apps/web/ui/partners/online-presence-form.tsx(8 hunks)apps/web/ui/partners/online-presence-summary.tsx(3 hunks)
🧰 Additional context used
🧠 Learnings (2)
apps/web/ui/partners/online-presence-summary.tsx (1)
Learnt from: devkiran
PR: dubinc/dub#2448
File: packages/email/src/templates/partner-program-summary.tsx:0-0
Timestamp: 2025-05-29T04:45:18.504Z
Learning: In the PartnerProgramSummary email template (packages/email/src/templates/partner-program-summary.tsx), the stat titles are hardcoded constants ("Clicks", "Leads", "Sales", "Earnings") that will always match the ICONS object keys after toLowerCase() conversion, so icon lookup failures are not possible.
apps/web/scripts/sanitize-social-handles.ts (1)
Learnt from: devkiran
PR: dubinc/dub#2177
File: apps/web/lib/api/links/bulk-create-links.ts:66-84
Timestamp: 2025-06-06T07:59:03.120Z
Learning: In apps/web/lib/api/links/bulk-create-links.ts, the team accepts the risk of potential undefined results from links.find() operations when building invalidLinks arrays, because existing links are fetched from the database based on the input links, so matches are expected to always exist.
🧬 Code Graph Analysis (4)
apps/web/ui/partners/online-presence-summary.tsx (1)
apps/web/lib/social-utils.ts (2)
sanitizeSocialHandle(48-85)SocialPlatform(1-6)
apps/web/scripts/sanitize-social-handles.ts (1)
apps/web/lib/social-utils.ts (2)
sanitizeSocialHandle(48-85)SocialPlatform(1-6)
apps/web/lib/actions/partners/update-online-presence.ts (1)
apps/web/lib/social-utils.ts (1)
sanitizeSocialHandle(48-85)
apps/web/ui/partners/online-presence-form.tsx (1)
apps/web/lib/social-utils.ts (1)
SocialPlatform(1-6)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (12)
apps/web/lib/social-utils.ts (3)
1-6: LGTM: Well-defined type union.The
SocialPlatformtype properly constrains the supported platforms and will provide good TypeScript support throughout the codebase.
48-85: Robust sanitization function with comprehensive validation.The function handles edge cases well and follows a logical sanitization flow. The implementation correctly:
- Validates input types and null/undefined values
- Removes URL prefixes and extracts handles using platform-specific patterns
- Applies character filtering and length constraints
- Returns null for invalid inputs
The logic is sound and should handle most real-world social media URL and handle formats.
14-46: Review platform configurations for accuracy.The platform configurations look comprehensive, but there are a few considerations:
YouTube patterns: The regex
/^@([^\/\?]+)/imay be too permissive for handles starting with@- it doesn't validate YouTube's specific handle requirements.TikTok max length: The 24-character limit seems correct, but verify this aligns with TikTok's current username requirements.
LinkedIn pattern: Consider if the pattern should also handle company pages (
/company/) in addition to personal profiles (/in/).What are the current username length limits and character requirements for YouTube, TikTok, and LinkedIn usernames?apps/web/ui/partners/online-presence-summary.tsx (3)
1-1: LGTM: Proper import of sanitization utilities.The import correctly brings in both the function and type from the new social-utils module.
55-55: LGTM: Updated label reflects current branding.Changing from "X/Twitter" to "X" aligns with the platform's current branding.
131-136: ```shell
#!/bin/bashLocate the sanitizeSocialHandle function in social-utils.ts
echo "Searching for sanitizeSocialHandle definition..."
rg -n "sanitizeSocialHandle" -A 10 apps/web/lib/social-utils.ts</details> <details> <summary>apps/web/scripts/sanitize-social-handles.ts (2)</summary> `6-27`: **LGTM: Efficient database query with safety limits.** The query properly filters for partners with social handles and uses pagination with a conservative limit of 10 records. The field selection is optimal, only fetching necessary data. --- `66-72`: **LGTM: Safe database update with proper error handling.** The update operation is properly isolated per partner with clear logging. The script structure allows for easy monitoring of changes. </details> <details> <summary>apps/web/lib/actions/partners/update-online-presence.ts (2)</summary> `7-7`: **LGTM: Proper import of sanitization function.** The import correctly brings in the sanitization utility for use in the schema transformations. --- `19-38`: **LGTM: Consistent sanitization across all social platforms.** The schema transformations properly apply sanitization to all social media handle inputs during validation. This ensures data consistency at the API boundary and complements the frontend sanitization. </details> <details> <summary>apps/web/ui/partners/online-presence-form.tsx (2)</summary> `77-77`: **LGTM: Added setValue for form field updates.** Properly adds `setValue` to the form destructuring to support the new paste handling logic. --- `210-210`: **LGTM: Consistent paste handling across all social inputs.** The paste handlers are properly applied to all social media input fields with the correct platform identifiers. Also applies to: 244-244, 278-278, 313-313, 351-351 </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
|
@coderabbitai full review, any breaking changes? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'll perform a comprehensive review and analyze potential breaking changes. Let me examine the codebase to understand the impact of these changes. 🏁 Script executed: Length of output: 11218 🏁 Script executed: Length of output: 17741 🏁 Script executed: Length of output: 3433 @devkiran After conducting a comprehensive review of the PR changes, I can provide you with a detailed analysis of potential breaking changes: 🔍 Full Review Summary✅ Non-Breaking Changes:
|
Summary by CodeRabbit
New Features
Refactor