Skip to content

fix: regex and id extraction for giphy media urls #22276

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abhix4
Copy link
Contributor

@abhix4 abhix4 commented Jul 4, 2025

What does this PR do?

Fixed the regular expression used for validation.
Correctly extracts the Giphy ID from the URL path.

Visual Demo (For contributors especially)

before:
Screenshot from 2025-07-04 22-51-26

after:
Screenshot from 2025-07-04 22-47-38

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Summary by cubic

Fixed Giphy URL validation and ID extraction to correctly handle different Giphy media URL formats.

  • Bug Fixes
    • Updated the regex to support more Giphy URL patterns.
    • Fixed extraction logic to get the correct Giphy ID.

Copy link

vercel bot commented Jul 4, 2025

@abhix4 is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jul 4, 2025
@graphite-app graphite-app bot requested a review from a team July 4, 2025 17:36
@github-actions github-actions bot added event-types area: event types, event-types 🐛 bug Something isn't working labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "fix regex and id extraction for giphy media urls". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@abhix4 abhix4 changed the title fix regex and id extraction for giphy media urls fix: regex and id extraction for giphy media urls Jul 4, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic reviewed 1 file and found no issues. Review PR in cubic.dev.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic reviewed 1 file and found no issues. Review PR in cubic.dev.

Copy link

graphite-app bot commented Jul 4, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (07/04/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (07/04/25)

1 label was added to this PR based on Keith Williams's automation.

Comment on lines +31 to +34
if (!matches || matches.length < 2) {
return res.status(400).json({ message: "Giphy URL is invalid" });
}
const giphyId = matches[2];
const giphyId = matches[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain this change?

@anikdhabal anikdhabal added the Low priority Created by Linear-GitHub Sync label Jul 16, 2025
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The changes update the regular expression used in the Giphy URL validation logic within packages/app-store/giphy/api/get.ts. The new regex is more precise, supporting both HTTP and HTTPS protocols, optional subdomains, and an optional version segment in the URL path. The logic for extracting the Giphy ID from the matched URL is updated to align with the new regex structure. No changes were made to the function signatures or exported entities.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Update Giphy URL validation to support media links (CAL-6046, #22275)
Ensure Giphy ID extraction works for new media URL formats (CAL-6046, #22275)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15b26df and 61d623c.

📒 Files selected for processing (1)
  • packages/app-store/giphy/api/get.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.ts

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/app-store/giphy/api/get.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/app-store/giphy/api/get.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: Anshumancanrock
PR: calcom/cal.com#22570
File: apps/web/modules/signup-view.tsx:253-253
Timestamp: 2025-07-21T21:33:23.371Z
Learning: In signup-view.tsx, when checking if redirectUrl contains certain strings, using explicit && checks (redirectUrl && redirectUrl.includes()) is preferred over optional chaining (redirectUrl?.includes()) to ensure the result is always a boolean rather than potentially undefined. This approach provides cleaner boolean contracts for downstream conditional logic.
packages/app-store/giphy/api/get.ts (1)

Learnt from: Anshumancanrock
PR: #22570
File: apps/web/modules/signup-view.tsx:253-253
Timestamp: 2025-07-21T21:33:23.371Z
Learning: In signup-view.tsx, when checking if redirectUrl contains certain strings, using explicit && checks (redirectUrl && redirectUrl.includes()) is preferred over optional chaining (redirectUrl?.includes()) to ensure the result is always a boolean rather than potentially undefined. This approach provides cleaner boolean contracts for downstream conditional logic.

🔇 Additional comments (2)
packages/app-store/giphy/api/get.ts (2)

6-8: Improved regex pattern supports broader range of Giphy URLs.

The updated regex pattern correctly handles:

  • Both HTTP and HTTPS protocols (https?)
  • Optional subdomains ((?:[\\w.-]+\\.)?)
  • Optional version segments in the path ((?:\\/v1\\.[^/]+)?)
  • Captures the Giphy ID as the first capture group (([^/]+))

This addresses the issues described in #22275 and CAL-6046 where media URLs like https://media1.giphy.com/media/v1.Y2lkPTc.../ngDR1qZBUIIEwJGPx7/giphy.gif were failing validation.


34-34: ID extraction correctly uses first capture group.

The Giphy ID extraction was properly updated from matches[2] to matches[1] to correspond with the new regex structure where the ID is captured as the first group.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added Stale and removed Stale labels Jul 31, 2025
@kart1ka kart1ka marked this pull request as draft August 11, 2025 17:27
@kart1ka
Copy link
Contributor

kart1ka commented Aug 11, 2025

Making it draft. Feel free to rfr once the comments are addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working community Created by Linear-GitHub Sync event-types area: event types, event-types Low priority Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Giphy URL Validation Fails for Media Links
3 participants