Skip to content
This repository
Browse code

Merge pull request #1416 from yakky/issue_1366

Fix for icon_url escape
  • Loading branch information...
commit 1e144b549589e028cd81c51b4bfcb558906cb174 2 parents e35e717 + c0f8606
Patrick Lauber authored September 12, 2012
2  cms/admin/placeholderadmin.py
@@ -225,7 +225,7 @@ def edit_plugin(self, request, plugin_id):
225 225
                 'name': unicode(saved_object), 
226 226
                 "type": saved_object.get_plugin_name(),
227 227
                 'plugin_id': plugin_id,
228  
-                'icon': force_escape(escapejs(saved_object.get_instance_icon_src())),
  228
+                'icon': force_escape(saved_object.get_instance_icon_src()),
229 229
                 'alt': force_escape(escapejs(saved_object.get_instance_icon_alt())),
230 230
             }
231 231
             return render_to_response('admin/cms/page/plugin_forms_ok.html', context, RequestContext(request))
16  cms/test_utils/project/placeholderapp/cms_plugins.py
... ...
@@ -0,0 +1,16 @@
  1
+from cms.plugin_pool import plugin_pool
  2
+from cms.plugin_base import CMSPluginBase
  3
+from django.utils.translation import ugettext_lazy as _
  4
+from django.conf import settings
  5
+
  6
+class EmptyPlugin(CMSPluginBase):
  7
+    name = _("Test Plugin")
  8
+    text_enabled = True
  9
+
  10
+    def render(self, context, instance, placeholder):
  11
+        return context
  12
+
  13
+    def icon_src(self, instance):
  14
+        return settings.STATIC_URL + u"plugins/empty-image-file.png"
  15
+
  16
+plugin_pool.register_plugin(EmptyPlugin)
46  cms/tests/placeholder.py
@@ -158,6 +158,52 @@ def test_inter_placeholder_plugin_move(self):
158 158
         self.assertEqual([ph1_pl1, ph1_pl3], list(ph1.cmsplugin_set.order_by('position')))
159 159
         self.assertEqual([ph2_pl1, ph1_pl2, ph2_pl2, ph2_pl3], list(ph2.cmsplugin_set.order_by('position')))
160 160
 
  161
+    def test_nested_plugin_escapejs(self):
  162
+        """
  163
+        Checks #1366 error condition.
  164
+        When adding/editing a plugin whose icon_src() method returns a URL
  165
+        containing an hyphen, the hyphen is escaped by django escapejs resulting
  166
+        in a incorrect URL
  167
+        """
  168
+        with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
  169
+            ex = Example1(
  170
+                char_1='one',
  171
+                char_2='two',
  172
+                char_3='tree',
  173
+                char_4='four'
  174
+            )
  175
+            ex.save()
  176
+            ph1 = ex.placeholder
  177
+            ###
  178
+            # add the test plugin
  179
+            ###
  180
+            test_plugin = add_plugin(ph1, u"EmptyPlugin", u"en")
  181
+            test_plugin.save()
  182
+            pl_url = "%sedit-plugin/%s/" % (
  183
+                reverse('admin:placeholderapp_example1_change', args=(ex.pk,)),
  184
+                test_plugin.pk)
  185
+            response = self.client.post(pl_url, {})
  186
+            self.assertContains(response,"/static/plugins/empty-image-file.png")
  187
+
  188
+    def test_nested_plugin_escapejs_page(self):
  189
+        """
  190
+        Sibling test of the above, on a page.
  191
+        #1366 does not apply to placeholder defined in a page
  192
+        """
  193
+        with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
  194
+            page = create_page('page', 'col_two.html', 'en')
  195
+            ph1 = page.placeholders.get(slot='col_left')
  196
+            ###
  197
+            # add the test plugin
  198
+            ###
  199
+            test_plugin = add_plugin(ph1, u"EmptyPlugin", u"en")
  200
+            test_plugin.save()
  201
+            pl_url = "%sedit-plugin/%s/" % (
  202
+                reverse('admin:cms_page_change', args=(page.pk,)),
  203
+                test_plugin.pk)
  204
+            response = self.client.post(pl_url, {})
  205
+            self.assertContains(response,"/static/plugins/empty-image-file.png")
  206
+
161 207
     def test_placeholder_scanning_fail(self):
162 208
         self.assertRaises(TemplateSyntaxError, get_placeholders, 'placeholder_tests/test_eleven.html')
163 209
 

0 notes on commit 1e144b5

Please sign in to comment.
Something went wrong with that request. Please try again.