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

3.7.8 Add json_for_script function to remove unicode data and escape HTML and XML #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cruz-evan
Copy link

Fixes an error where navigating to the upload page results in a javascript "unexpected string error" error and causing the upload button to not appear on the page. Since mark_safe causes all of the values in the extentions to become unicode this error happens.

Original django-filebrowser 3.7.x does not have mark-safe on the get_file_extentions function.
https://github.com/sehmaschine/django-filebrowser/blob/stable/3.7.x/filebrowser/templatetags/fb_tags.py

-Similar implementation to Django 2.1 function json_script
-Fixes the problem where the upload button would not appear if the list had unicode data inside

@DylanYoung
Copy link

DylanYoung commented Jun 10, 2019

@cruz-evan Looks like there's a test that needs fixing (quotes are now reversed):

FAIL: test_get_filtered (tests.test_templatetags.GetFileExtensionsTemplateTagTests)

Traceback (most recent call last):
File "/home/travis/build/smacker/django-filebrowser-no-grappelli/tests/test_templatetags.py", line 21, in test_get_filtered
"['.jpg', '.jpeg', '.gif', '.png', '.tif', '.tiff']"
AssertionError: '[".jpg", ".jpeg", ".gif", ".png", ".tif", ".tiff"]' != "['.jpg', '.jpeg', '.gif', '.png', '.tif', '.tiff']"`

filebrowser/utils.py Outdated Show resolved Hide resolved
…HTML and XML

-Similar implementation to Django 2.1 function json_script
-Fixes the problem where the upload button would not appear if the list had unicode data inside
@@ -18,5 +18,5 @@ def test_get_all(self):
def test_get_filtered(self):

Choose a reason for hiding this comment

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

@cruz-evan If you unify this with the way the above test is written (as in our fork), then you don't need to worry about these small formatting differences. Probably it should use json.loads instead of eval, since this is the context wherein we hit the issue that necessitated this PR.

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