Anonymous avatar Anonymous committed 74b241b

[svn] Adding js_obfuscate function for Javascript obfuscation.

Comments (0)

Files changed (1)

webhelpers/rails/urls.py

         return javascript_tag("eval(unescape('%s'))" % string)
     else : 
         return tag
+
+def js_obfuscate(data):
+    """Obfuscates data in a Javascript tag
     
+    Example::
+        
+        >>> js_obfuscate("<input type='hidden' name='check' value='valid' />")
+        '<script type="text/javascript">\n//<![CDATA[\neval(unescape(\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%69%6e%70%75%74%20%74%79%70%65%3d%27%68%69%64%64%65%6e%27%20%6e%61%6d%65%3d%27%63%68%65%63%6b%27%20%76%61%6c%75%65%3d%27%76%61%6c%69%64%27%20%2f%3e%27%29%3b\'))\n//]]>\n</script>'
+    """
+    tmp = "document.write('%s');" % data
+    string = ''.join(['%%%x' % ord(x) for x in tmp])
+    return javascript_tag("eval(unescape('%s'))" % string)
 
 __all__ = ['url', 'link_to', 'button_to', 'link_to_unless_current', 'link_to_unless', 'link_to_if',
-           'current_page', 'current_url', 'mail_to']
+           'current_page', 'current_url', 'mail_to', 'js_obfuscate']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.