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

Scape simple quotes to avoid javascript warnings if not properly used #1045

Closed
wants to merge 1 commit into from
Closed

Conversation

mariocesar
Copy link

No description provided.

@ojii
Copy link
Contributor

ojii commented Oct 11, 2011

Are those quotes really required?

@mariocesar
Copy link
Author

The issue is that the english translation doesn't have inside quotes and spanish translation does.

<script type="text/javascript">
    //<![CDATA[
    // dynamic variables for the toolbar js file
    var placeholder_data = {};
    var page_is_defined = true;
    var translations = {
        move_slot: 'Mover a %(name)s',
        question: '¿Seguro que desea eliminar este 'plugin'?'
    };
    # ...
</script>

This obviously will not work. '¿Seguro que desea eliminar este 'plugin'?' needs to scape the inside simple quotes in order for the javascript code be valid.

I am not sure what would be the best if changing the translations, or escaping the lines on the templates.

@ojii
Copy link
Contributor

ojii commented Oct 11, 2011

I think we need a better way to solve this. It happened all the time (always spanish for some reason...). We probably need something like {% js_escaped_trans "mystring" %} or whatever...

@mariocesar
Copy link
Author

I agree about filtering instead of changing the translation.

I made some commits on my fork:
244114c4d757f13b0488dcb901da1f4baa0d78a3
897eb0ef557db9efa313d632c4263306dacde250
d7b24a3bfb8e94bcd58d7e30be68f1b4f72b613d

This will escape the javascript strings to make it safe, added a new filter js_string on the js.py templatetag

@mariocesar
Copy link
Author

I am closing this pull request, and open this other #1046 with the js_string filter.

Thanks for the time, I fix the problem for my sites, that is great :-)

@mariocesar mariocesar closed this Oct 11, 2011
@ojii
Copy link
Contributor

ojii commented Oct 11, 2011

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.

None yet

2 participants