-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
# POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
|
||
from urllib.parse import unquote, urlparse | ||
from gi.repository import GObject, Gedit | ||
from .shared import EditorConfigPluginMixin | ||
|
||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) ( |
||
return {} |
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.
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.
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.
Hmm. It seems that while
document.get_uri()
returned agchar
string containing the URI, there was also adocument.get_location()
which, similar to GEdit 3, returned an ancient-history version of aGFile
. (ref)What did the
GFile
API look like in 2010, tho? Absolutely no idea.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.
...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 neitherhas_uri_scheme()
norget_path()
is shown as being a later addition to theGFile
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 ofdocument.get_file().get_location()
.