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

fix out of index error when install source is not standard github link #3054

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

taooceros
Copy link
Member

@taooceros taooceros commented Oct 29, 2024

fix #3017

@prlabeler prlabeler bot added the bug Something isn't working label Oct 29, 2024
@github-actions github-actions bot added this to the 1.19.4 milestone Oct 29, 2024
@taooceros taooceros requested a review from jjw24 October 29, 2024 05:24
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
❌ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request focus on the PluginsManager class within PluginsManager.cs. Key modifications include enhancements to the RequestUpdateAsync method for better handling of local plugin updates, improved logic in the InstallFromLocalPath method for unknown sources, and a refactoring of the InstallSourceKnown method to streamline source checks. Minor formatting adjustments were made for readability, and error handling in the Install method was refined to ensure proper logging of exceptions.

Changes

File Path Change Summary
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs - Modified RequestUpdateAsync for local plugin updates.
- Updated InstallFromLocalPath for unknown sources.
- Refactored InstallSourceKnown for clarity in source checks.
- Minor formatting changes for readability.
- Enhanced error handling in Install method.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PluginsManager
    participant PluginSource

    User->>PluginsManager: Request plugin update
    PluginsManager->>PluginSource: Check local zip path
    PluginSource-->>PluginsManager: Return plugin data
    PluginsManager->>PluginsManager: Process plugin update
    PluginsManager->>User: Confirm update completion
Loading

🐰 "In the code where plugins play,
A twist and turn, a bright new day.
With paths and sources all refined,
A hop, a skip, our goals aligned.
So let us cheer, with joy we sing,
For every change, new life they bring!" 🐇


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>, please review it.
    • 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 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 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 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 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

@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

🧹 Outside diff range and nitpick comments (1)
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (1)

535-540: Good fix for the out-of-index error, consider additional URL validation

The changes properly handle the array bounds checking before accessing URL segments, fixing the original issue. However, consider adding more robust URL validation:

Consider these improvements:

 private bool InstallSourceKnown(string url)
 {
+    if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
+        return false;
+
     var pieces = url.Split('/');
 
     if (pieces.Length < 4)
         return false;
 
     var author = pieces[3];
+    // Handle encoded characters in the author segment
+    author = Uri.UnescapeDataString(author);
     var acceptedSource = "https://github.com";
     var constructedUrlPart = string.Format("{0}/{1}/", acceptedSource, author);
 
     return url.StartsWith(acceptedSource) &&
            Context.API.GetAllPlugins().Any(x => x.Metadata.Website.StartsWith(constructedUrlPart));
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 009f71a and a9da2af.

📒 Files selected for processing (1)
  • Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (5 hunks)
🔇 Additional comments (2)
Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs (2)

206-210: LGTM! Code readability improvement

The changes make the update source selection logic more concise and clearer to understand.


Line range hint 535-544: Verify similar URL validation patterns in the codebase

While the fix addresses the immediate issue, it would be good to verify other places where GitHub URLs are parsed.

✅ Verification successful

Based on the search results, I can see that GitHub URL handling is primarily used in the context of plugin management, updates, and documentation links. The specific URL validation pattern in the review (splitting and checking URL parts) is only used in the PluginsManager.cs file for validating plugin sources.

Let me verify if there are any other URL splitting patterns that might need similar validation:


No similar URL validation patterns require attention

The search results show that URL splitting and validation patterns are only used in two specific contexts:

  • PluginsManager.cs: For validating GitHub plugin sources (the code under review)
  • Win32.cs: For resolving Windows shortcut paths with protocol handlers, which is a different use case

The current validation in PluginsManager.cs is sufficient as it's the only place where GitHub repository URLs need to be validated for plugin management.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for URL splitting patterns that might need similar validation
rg -l 'Split\(["/'']\)' | while read -r file; do
  echo "=== $file ==="
  rg -A 5 'Split\(["/'']\)' "$file"
done

# Search for GitHub URL handling
rg -l 'github\.com' | while read -r file; do
  echo "=== $file ==="
  rg -A 5 'github\.com' "$file"
done

Length of output: 76693


Script:

#!/bin/bash
# Search for URL splitting patterns in the codebase
ast-grep --pattern 'Split($_, $_)'

# Also search for URL validation patterns
rg -A 5 'url\.(StartsWith|Contains|EndsWith)'

Length of output: 1341

@jjw24 jjw24 merged commit 350423b into dev Oct 31, 2024
6 of 9 checks passed
@jjw24 jjw24 deleted the fix-install-source-author branch October 31, 2024 10:46
@jjw24 jjw24 mentioned this pull request Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: When installing local plugin, crash when website is not correct
2 participants