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 unable to parse filename with spaces #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions editorconfig_plugin/gedit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#

import gedit
from urllib.parse import unquote, urlparse
from .shared import EditorConfigPluginMixin


Expand All @@ -39,6 +40,5 @@ def get_document_properties(self, document):
"""Call EditorConfig core and return properties dict for document"""
if document:
file_uri = document.get_uri()
if file_uri and file_uri.startswith("file:///"):
return self.get_properties_from_filename(file_uri[7:])
return self.get_properties_from_filename(unquote(urlparse(file_uri).path))
return {}
4 changes: 2 additions & 2 deletions editorconfig_plugin/gedit3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# POSSIBILITY OF SUCH DAMAGE.
#

from urllib.parse import unquote, urlparse
from gi.repository import GObject, Gedit
from .shared import EditorConfigPluginMixin

Expand All @@ -44,6 +45,5 @@ def get_document_properties(self, document):
location = document.get_file().get_location()
if location:
file_uri = location.get_uri()
if file_uri.startswith('file:///'):
return self.get_properties_from_filename(file_uri[7:])
return self.get_properties_from_filename(unquote(urlparse(file_uri).path))
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong to me, because what if the file_uri is something like sftp://host.domain/path/to/some%20remote%20file.txt? At least in theory that's possible, with Gio... so it seems like the if file_uri.startswith('file:///') check is still necessary, no?

In fact, I just ran gedit sftp://my.fileserver/home/ferd/.zshrc and GEdit opened up my remote .zshrc just fine. But it'd break things, if the plugin turns that location into the path to my local .zshrc. (Which also exists, but is not the same file!)

If the file_uri does start with file:///, I agree using urlparse and unquote is a better approach to converting URLs into local pathnames.

Copy link
Author

Choose a reason for hiding this comment

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

Alright thanks for the correction. So I guess it's better to keep the file:/// URI checking then, let me fix this soon

return {}