Skip to content
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

[lexical][auto-link] Fix auto link node escapes on second "." #36

Open
wants to merge 2 commits into
base: cloned_main_0de58
Choose a base branch
from

Conversation

local-dev-korbit-ai-mentor[bot]
Copy link

@local-dev-korbit-ai-mentor local-dev-korbit-ai-mentor bot commented Aug 15, 2024

Description

The period in the separators list PUNCTUATION_OR_SPACE leads to an auto-link creation prematurely before the user completes typing. Removing the "." from the list.
Inspired by facebook/lexical#5275 which was reverted because of Regexp changes.

Closes: #5254 #3546

Test plan

  1. Open https://playground.lexical.dev/
  2. Type "https://www.foo.com"
  3. See that the link is created for the full URL.

Before

Screen.Recording.2024-05-20.at.12.13.38.mov

After

Screen.Recording.2024-05-20.at.12.14.09.mov

Description by Korbit AI

Note

This feature is in early access. You can enable or disable it in the Korbit Console.

What change is being made?

Fix auto-link node escapes on second "." by updating the URL regex and adding tests for valid and invalid URLs.

Why are these changes being made?

The previous implementation failed to correctly handle URLs with multiple periods, causing incorrect link generation. The updated regex and additional tests ensure robust URL detection and conversion, improving the auto-link functionality.

Summary by CodeRabbit

  • New Features

    • Enhanced URL detection with improved pattern matching, reducing false positives in link conversion.
    • Introduced a new function to check text content conditions for more nuanced auto-linking behavior.
  • Bug Fixes

    • Added test cases to ensure valid URLs convert correctly and invalid URLs do not convert, enhancing the robustness of URL handling.
  • Documentation

    • Improved test coverage documentation for URL handling functionality.

Copy link
Author

Clone of the PR facebook/lexical#6146

Copy link

korbit-ai bot commented Aug 15, 2024

My review is in progress 📖 - I will have feedback for you in a few minutes!

Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

The recent updates enhance the URL handling capabilities of the application. New tests ensure valid URLs are converted to links while invalid URLs remain unaltered, improving overall robustness. Additionally, the URL detection logic has been refined with an updated regex and new functions to handle specific text conditions, allowing for more accurate link creation and processing.

Changes

File Path Change Summary
packages/lexical-playground/__tests__/e2e/AutoLinks.spec.mjs Added two test cases for "Auto Links": one for validating the conversion of valid URLs into links and another for confirming that invalid URLs are not converted.
packages/lexical-playground/src/plugins/AutoLinkPlugin/index.tsx Modified URL_REGEX to enhance URL detection by adding a negative lookbehind assertion, improving the accuracy of matching valid URLs.
packages/lexical-react/src/LexicalAutoLinkPlugin.ts Introduced a new function startsWithFullStop and modified handleBadNeighbors to improve text handling for auto-linking by checking conditions around text nodes.

Poem

🐇 In the garden where links grow bright,
A bunny hops with pure delight.
URLs now, both good and bad,
Are handled well, oh, how I’m glad!
With regex sharp and tests in play,
We’ll link the world in a grand way! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@korbit-ai korbit-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.

I have reviewed your code and found 1 potential issue.

@@ -13,7 +13,7 @@ import {
import * as React from 'react';

const URL_REGEX =
/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)(?<![-.+():%])/;
Copy link

Choose a reason for hiding this comment

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

category Functionality

The modification to the URL_REGEX pattern adds a negative lookbehind assertion (?<![-.+():%]) at the end. While this change aims to prevent premature link creation, it might be too restrictive. Consider testing with a variety of valid URL formats to ensure that this change doesn't inadvertently prevent the recognition of legitimate URLs that end with these characters. You might need to refine the regex further to balance between preventing premature linking and recognizing all valid URL formats.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

@furwellness
Copy link
Owner

/review

Copy link

codiumai-pr-agent-free bot commented Aug 16, 2024

PR Reviewer Guide 🔍

(Review updated until commit 24c3000)

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Key issues to review

Regex Complexity
The updated URL_REGEX is complex and might be prone to ReDoS (Regular Expression Denial of Service) attacks if not properly handled. Consider simplifying the regex or implementing additional safeguards.

Logic Change
The logic change in handleBadNeighbors function to include startsWithFullStop might affect existing functionality. Ensure this change doesn't introduce bugs with edge cases.

Copy link

Persistent review updated to latest commit 24c3000

@furwellness
Copy link
Owner

@coderabbitai review

Copy link

coderabbitai bot commented Aug 17, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0de58bb and 24c3000.

Files selected for processing (3)
  • packages/lexical-playground/tests/e2e/AutoLinks.spec.mjs (1 hunks)
  • packages/lexical-playground/src/plugins/AutoLinkPlugin/index.tsx (1 hunks)
  • packages/lexical-react/src/LexicalAutoLinkPlugin.ts (2 hunks)
Additional comments not posted (5)
packages/lexical-playground/src/plugins/AutoLinkPlugin/index.tsx (1)

16-16: Verify the regex change for broader URL support.

The modification to the URL_REGEX pattern adds a negative lookbehind assertion (?<![-.+():%]). While this change aims to prevent premature link creation, it might be too restrictive. Consider testing with a variety of valid URL formats to ensure that this change doesn't inadvertently prevent the recognition of legitimate URLs that end with these characters.

packages/lexical-react/src/LexicalAutoLinkPlugin.ts (2)

92-94: Function startsWithFullStop added.

The function startsWithFullStop checks if text content starts with a full stop followed by alphanumeric characters. This addition seems to be aimed at handling edge cases in URL detection.


383-386: Review the updated logic in handleBadNeighbors.

The logic now includes a check for startsWithFullStop. Ensure this change aligns with the intended behavior of handling URLs and does not introduce unintended side effects.

packages/lexical-playground/__tests__/e2e/AutoLinks.spec.mjs (2)

386-467: Comprehensive test coverage for valid URLs.

The test case "Can convert URLs into links" covers a wide range of valid URL formats. This is a thorough approach to ensure the correctness of URL conversion logic.


469-515: Comprehensive test coverage for invalid URLs.

The test case "Can not convert bad URLs into links" covers various invalid URL scenarios. This ensures that the system correctly identifies and handles invalid URL inputs.

@furwellness
Copy link
Owner

Zero comments from coderabbit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant