Skip to content

Conversation

@hakanensari
Copy link
Contributor

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

  • Modified UriHelper.uri_to_path to properly decode URI-encoded file paths
  • Added test coverage for files with spaces in their paths

Test plan

  • Added unit tests for URI decoding with spaces
  • Manually tested with files containing spaces in their paths
  • Existing tests pass

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

@hakanensari hakanensari deleted the fix-lsp-uri-encoded-paths branch July 27, 2025 22:11
@hakanensari hakanensari restored the fix-lsp-uri-encoded-paths branch July 27, 2025 22:13
@hakanensari hakanensari reopened this Jul 27, 2025
@hakanensari
Copy link
Contributor Author

Related issue: zed-extensions/ruby#139

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 28, 2025

The changes look reasonable to me. Please, take a look at the failing tests on 2.7 and 3.0.

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://'))
Copy link
Member

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.

@hakanensari hakanensari force-pushed the fix-lsp-uri-encoded-paths branch from 6fc926a to 2d7020d Compare July 28, 2025 09:19
def remove_file_protocol_from(uri)
uri.delete_prefix('file://')
def convert_file_uri_to_path(uri)
require 'cgi'
Copy link
Contributor

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 methods

https://bugs.ruby-lang.org/issues/21258

Also this should probably be eagerly required, not only at method call. All of rubocop is done that way

Copy link
Contributor Author

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.

Copy link
Contributor

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

@hakanensari hakanensari force-pushed the fix-lsp-uri-encoded-paths branch from 02d07f0 to a73d600 Compare July 28, 2025 09:50
@koic
Copy link
Member

koic commented Jul 28, 2025

Can you add a changelog entry? Please refer to the original PR template for guidance on how to write it.

https://github.com/rubocop/rubocop/blob/v1.79.0/.github/PULL_REQUEST_TEMPLATE.md

@hakanensari hakanensari force-pushed the fix-lsp-uri-encoded-paths branch from a73d600 to 220828b Compare July 28, 2025 15:39
@koic
Copy link
Member

koic commented Jul 28, 2025

@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
@hakanensari hakanensari force-pushed the fix-lsp-uri-encoded-paths branch from ac4d0f5 to d53899d Compare July 28, 2025 17:57
@koic koic merged commit 423d158 into rubocop:master Jul 28, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants