forked from timlockridge/SublimeEvernote
-
Notifications
You must be signed in to change notification settings - Fork 104
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
I found a bug from"evernote: insert attachment here" in windows #137
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when I press the command evernote: insert attachment here,i was asked to type a filename(what i type is:"C:/123.jpg") .But i got an error message : error: Evernote plugin has troubles locating the specified file/URL. Evernote plugin error, please see the console for more details. Then contact developer at https://github.com/bordaigorl/sublime-evernote/issues Evernote plugin error: <urlopen error unknown url type: g> After I search the google, i found there are something wrongs in the source code(line 1114): https://github.com/bordaigorl/sublime-evernote/blob/master/sublime_evernote.py#L1113 Relate code: if urllib.parse.urlparse(filename).scheme != "": # download response = urllib.request.urlopen(filename) filecontents = response.read() attr = {"sourceURL": filename} mimet = response.info().get_content_type() else: datafile = os.path.expanduser(filename) with open(datafile, 'rb') as content_file: filecontents = content_file.read() attr = {"fileName": os.path.basename(datafile)} where "urllib.parse.urlparse(filename).scheme" in windows, filename will be "C:/123.jpg" and this statement will return a "C" ,so the filename "C:/123.jpg" will be considered as an url according to this code. so one of the solution for this bug in windows is that: if urllib.parse.urlparse(filename).scheme != "" and urllib.parse.urlparse(filename).scheme not in [chr(i) for i in range(97,123)] : # download response = urllib.request.urlopen(filename) filecontents = response.read() attr = {"sourceURL": filename} mimet = response.info().get_content_type() else: datafile = os.path.expanduser(filename) with open(datafile, 'rb') as content_file: filecontents = content_file.read() attr = {"fileName": os.path.basename(datafile)} use this statement instead urllib.parse.urlparse('c:/123.jpg').scheme not in [chr(i) for i in range(97,123)] which means that to find out if the 'C' is a letter, so as to separate the area HTTPS FTP HTTP and orther urls e.g. >>> filename='http://www.google.com/123.jpg' >>> urllib.parse.urlparse(filename).scheme != "" and urllib.parse.urlparse(filename).scheme not in [chr(i) for i in range(97,123)] True >>> filename="/123/123.jpg" >>> urllib.parse.urlparse(filename).scheme != "" and urllib.parse.urlparse(filename).scheme not in [chr(i) for i in range(97,123)] False >>> filename='c:/123.jpg' >>> urllib.parse.urlparse(filename).scheme != "" and urllib.parse.urlparse(filename).scheme not in [chr(i) for i in range(97,123)] False
Hi @358463121 thanks for your contribution. I think the correct patch for this is not by insisting in using urlparse but by checking if the string is a file, i.e. substituting the urlparse check with |
bordaigorl
added a commit
that referenced
this pull request
Jun 12, 2016
Use of urlparse to check if string is url wrongly interpreted `C:/path` as an url.
Hi, thanks again for the contribution. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
when I press the command evernote: insert attachment here,i was asked to
type a filename("C:/123.jpg") .But i got an error message
:
error: Evernote plugin has troubles locating the specified file/URL.
Evernote plugin error, please see the console for more details.
Then contact developer at
https://github.com/bordaigorl/sublime-evernote/issues
Evernote plugin error:
After I search the google, i found there are something wrongs in the
source code(line 1114):
https://github.com/bordaigorl/sublime-evernote/blob/master/sublime_evernote.py#L1113
Related code:
where
urllib.parse.urlparse(filename).scheme
in windows, filename willbe "C:/123.jpg"
and this statement will return a "C" ,so the filename "C:/123.jpg"
will be considered as an url according to this code.
so one of the solution for this bug in windows is that:
use this statement instead
which means that to find out if the 'C' is a letter, so as to separate
the area HTTPS FTP HTTP and orther urls
e.g.