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 all commits
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
5 changes: 3 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,6 @@ 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:])
if file_uri and file_uri.startswith('file://'):
return self.get_properties_from_filename(unquote(urlparse(file_uri).path))
Comment on lines -42 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll have to track down GEdit 2 API documentation, to figure out if this one can use similar calls. Though it's debatable whether providing a gedit2 plugin really makes any sense anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. It seems that while document.get_uri() returned a gchar string containing the URI, there was also a document.get_location() which, similar to GEdit 3, returned an ancient-history version of a GFile. (ref)

What did the GFile API look like in 2010, tho? Absolutely no idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

...Huh, I guess even back in 2010 GFile was provided by Gio, which means its API should be fairly similar to what it is today. GLib has evolved very little over the years. And neither has_uri_scheme() nor get_path() is shown as being a later addition to the GFile API, so they should exist just the same even in GEdit 2.

Looks like this one can be written the same as in GEdit 3, just using document.get_location() instead of document.get_file().get_location().

return {}
5 changes: 3 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,6 @@ 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:])
if file_uri.startswith('file://'):
return self.get_properties_from_filename(unquote(urlparse(file_uri).path))
Comment on lines 46 to +49
Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies, @michaelrk02, for not checking this out earlier, but I was just reading the terminal plugin source, and it turns out this plugin is using outdated APIs. This function can be written like this, and not require urllib at all:

location = document.get_file().get_location()
if location and location.has_uri_scheme('file'):
    return self.get_properties_from_filename(location.get_path())

(document.get_file() returns a GtkSourceFile, and its get_location() method returns a GFile with access to all of that interface's methods.)

return {}