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

Issue 1 #2

Merged
merged 5 commits into from
Jan 13, 2017
Merged

Issue 1 #2

merged 5 commits into from
Jan 13, 2017

Conversation

tundebabzy
Copy link
Contributor

I created a test case that validates the issue and added a fix.

Copy link
Owner

@klis87 klis87 left a comment

Choose a reason for hiding this comment

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

I added one comment to your commits, thanks in advance for reviewing it.

@@ -101,7 +101,7 @@ def _prepend_prefix(self, name):
prefix = self._normalize_path(prefix)
if not name.startswith(prefix):
name = prefix + name
return name
return name.replace('\\', '/')
Copy link
Owner

Choose a reason for hiding this comment

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

I think line 104 could be extracted as separate method for readability, such as:

def _convert_to_unix_path(path):
    return path.replace('\\', '/')

Then it could be used at the beginning of _save, like:

def _save(self, name, content):
    name = self._convert_to_unix_path(name)
    name = self._prepend_prefix(name)
    content = UploadedFile(content, name)
    response = self._upload(name, content)
    return response['public_id']

Apart from readability, it would be a little safer as replacing backslashes with slashes at the end of _prepend_prefix is dangerous as for example _normalize_path would append unnecessary / to windows style path due to if path != '' and not path.endswith('/') condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very true. I'll fix that ASAP

@tundebabzy
Copy link
Contributor Author

Instead of _convert_to_unix_path, I opted to name the method _normalise_name to make it clear that we are dealing with a name and not a path.

@klis87 klis87 merged commit 51d2179 into klis87:master Jan 13, 2017
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.

2 participants