-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix LSP handling of URI-encoded paths with spaces #14395
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
|
Related issue: zed-extensions/ruby#139 |
|
The changes look reasonable to me. Please, take a look at the failing tests on 2.7 and 3.0. |
lib/rubocop/lsp/routes.rb
Outdated
| def remove_file_protocol_from(uri) | ||
| uri.delete_prefix('file://') | ||
| def convert_file_uri_to_path(uri) | ||
| URI.decode_uri_component(uri.delete_prefix('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.
AFAIK, URI.decode_uri_component was introduced in Ruby 3.1. Since RuboCop supports Ruby 2.7+, an appropriate API needs to be selected accordingly.
6fc926a to
2d7020d
Compare
lib/rubocop/lsp/routes.rb
Outdated
| def remove_file_protocol_from(uri) | ||
| uri.delete_prefix('file://') | ||
| def convert_file_uri_to_path(uri) | ||
| require 'cgi' |
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.
This unfortunatly won't work with Ruby 3.5 as it will emit a deprecation warning on that version. You need to replace it with this:
require "cgi/escape" # Includes escape/unescape methods on Ruby 3.5
require "cgi/util" if RUBY_VERSION < "3.5" # Required on earlier version for the unescape methodsAlso this should probably be eagerly required, not only at method call. All of rubocop is done that way
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.
@Earlopain sorry, that was Claude. I switched to URI.decode_www_form_component, which should do the job.
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.
Yes, I think that should work. Much nicer, thanks. I keep forgetting where all these decode methods are and their subtle differences
02d07f0 to
a73d600
Compare
|
Can you add a changelog entry? Please refer to the original PR template for guidance on how to write it.
|
a73d600 to
220828b
Compare
|
@hakanensari Can you squash commits into one? |
When a project is located in a path containing spaces (e.g., on an external drive like `/Volumes/My Drive/project`), RuboCop's LSP implementation would fail to find the `.rubocop.yml` config file because it was looking for it at the URI-encoded path (with %20) instead of the actual file system path. This fix ensures that file URIs are properly decoded before being used for file system operations, allowing RuboCop to correctly locate config files in directories with spaces. Fixes zed-extensions/ruby#139
ac4d0f5 to
d53899d
Compare
Summary
This PR fixes an issue where RuboCop's LSP server incorrectly handles URI-encoded file paths containing spaces, causing cop functionality to fail for files with spaces in their paths.
Changes
UriHelper.uri_to_pathto properly decode URI-encoded file pathsTest plan
Fixes the issue where RuboCop LSP would fail to process files with spaces in their paths due to improper URI decoding.
🤖 Generated with Claude Code