Skip to content

Commit

Permalink
[fc] Repository: plone.app.content
Browse files Browse the repository at this point in the history
Branch: refs/heads/master
Date: 2015-06-25T03:10:04+02:00
Author: Johannes Raggam (thet) <raggam-nl@adm.at>
Commit: plone/plone.app.content@9927a52

Let @@getVocabulary return the vocabulary's value instead of the token for the id in the result set. The token is binary encoded and leads to encoding errors when selecting a value with non-ASCII data from vocabulary list in a select2 based widget.  Fixes: plone/Products.CMFPlone#650

Files changed:
M CHANGES.rst
M plone/app/content/browser/vocabulary.py
M plone/app/content/tests/test_widgets.py
Repository: plone.app.content
Branch: refs/heads/master
Date: 2015-06-25T10:57:01+02:00
Author: Johannes Raggam (thet) <raggam-nl@adm.at>
Commit: plone/plone.app.content@62bbf28

Merge pull request #34 from plone/thet-vocabularyencoding

Fix encoding problems with Mockup Select2 widget

Files changed:
M CHANGES.rst
M plone/app/content/browser/vocabulary.py
M plone/app/content/tests/test_widgets.py
  • Loading branch information
thet committed Jun 25, 2015
1 parent 6fef2f0 commit c2ab901
Showing 1 changed file with 138 additions and 186 deletions.
324 changes: 138 additions & 186 deletions last_commit.txt
Original file line number Diff line number Diff line change
@@ -1,230 +1,182 @@
Repository: Products.PortalTransforms
Repository: plone.app.content


Branch: refs/heads/master
Date: 2015-06-24T11:00:09+02:00
Author: Godefroid Chapelle (gotcha) <gotcha@bubblenet.be>
Commit: https://github.com/plone/Products.PortalTransforms/commit/9aafffdec8cc031206d8785139a4927d67cce256
Date: 2015-06-25T03:10:04+02:00
Author: Johannes Raggam (thet) <raggam-nl@adm.at>
Commit: https://github.com/plone/plone.app.content/commit/9927a5251bcf3b7a9262ee85a097d45d32181300

fix safe_html with entities after a &lt;script&gt; tag
Let @@getVocabulary return the vocabulary's value instead of the token for the id in the result set. The token is binary encoded and leads to encoding errors when selecting a value with non-ASCII data from vocabulary list in a select2 based widget. Fixes: https://github.com/plone/Products.CMFPlone/issues/650

Files changed:
M CHANGES.rst
M Products/PortalTransforms/tests/test_transforms.py
M Products/PortalTransforms/transforms/safe_html.py
M plone/app/content/browser/vocabulary.py
M plone/app/content/tests/test_widgets.py

diff --git a/CHANGES.rst b/CHANGES.rst
index 8450ec6..bc9c368 100644
index 9e9d820..7fca280 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,9 @@ Changelog
2.1.7 (unreleased)
@@ -4,7 +4,12 @@ Changelog
3.0.7 (unreleased)
------------------

+- fix safe_html with entities after a <script> tag
+ [gotcha]
+
- Remove CMFDefault dependency
[tomgross]
-- Nothing changed yet.
+- Let ``@@getVocabulary`` return the vocabulary's value instead of the token
+ for the id in the result set. The token is binary encoded and leads to
+ encoding errors when selecting a value with non-ASCII data from vocabulary
+ list in a select2 based widget.
+ Fixes: https://github.com/plone/Products.CMFPlone/issues/650
+ [thet]

diff --git a/Products/PortalTransforms/tests/test_transforms.py b/Products/PortalTransforms/tests/test_transforms.py
index 1dce9ef..98e214c 100644
--- a/Products/PortalTransforms/tests/test_transforms.py
+++ b/Products/PortalTransforms/tests/test_transforms.py
@@ -1,3 +1,4 @@
+# -*- coding: utf8 -*-
import os
import copy
import logging
@@ -214,12 +215,63 @@ def test_script(self):
data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
self.assertEqual(data.getData(), orig)

+ def test_unicode_in_script(self):
+ orig = ('<script type="text/javascript">'
+ ' $("h1 > ul").attr("alt", "Officiële");'
+ '</script>'
+ )
+ data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
+ self.assertEqual(data.getData(), orig)
+
def test_entities(self):
orig = "<code>a > 0 && b < 1</code>"
escaped = "<code>a &gt; 0 &amp;&amp; b &lt; 1</code>"
data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
self.assertEqual(data.getData(), escaped)
3.0.6 (2015-06-05)
diff --git a/plone/app/content/browser/vocabulary.py b/plone/app/content/browser/vocabulary.py
index 9754fc3..9108a20 100644
--- a/plone/app/content/browser/vocabulary.py
+++ b/plone/app/content/browser/vocabulary.py
@@ -153,7 +153,7 @@ def __call__(self):
items.append(item)
else:
for item in results:
- items.append({'id': item.token, 'text': item.title})
+ items.append({'id': item.value, 'text': item.title})

+ def test_script_with_entities_and_unicode(self):
+ orig = ('<script type="text/javascript">'
+ ' var el = "test";'
+ '</script>'
+ '<p>(KU&nbsp;Loket) Officiële inschrijvingen </p>'
+ )
+ data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
+ self.assertEqual(data.getData(), orig)
+
+ def test_script_with_entities(self):
+ orig = ('<script type="text/javascript">'
+ ' var el = "test";'
+ '</script>'
+ '<p>(KU&nbsp;Loket)</p>'
+ )
+ data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
+ self.assertEqual(data.getData(), orig)
+
+ def test_entities_with_script(self):
+ orig = ('<p>(KU&nbsp;Loket)</p>'
+ '<script type="text/javascript">'
+ ' var el = "test";'
+ '</script>'
+ )
+ data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
+ self.assertEqual(data.getData(), orig)
+
+ def test_script_with_unicode(self):
+ orig = ('<script type="text/javascript">'
+ ' var el = "test";'
+ '</script>'
+ '<p>Officiële inschrijvingen </p>'
+ )
+ data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
+ self.assertEqual(data.getData(), orig)
if total == 0:
total = len(items)
diff --git a/plone/app/content/tests/test_widgets.py b/plone/app/content/tests/test_widgets.py
index be32820..ba4a7b6 100644
--- a/plone/app/content/tests/test_widgets.py
+++ b/plone/app/content/tests/test_widgets.py
@@ -15,6 +15,7 @@
from plone.app.widgets.testing import ExampleVocabulary
from plone.app.widgets.testing import PLONEAPPWIDGETS_INTEGRATION_TESTING
from plone.app.widgets.testing import TestRequest
+from zope.component import getMultiAdapter
from zope.component import provideAdapter
from zope.component import provideUtility
from zope.component.globalregistry import base
@@ -175,6 +176,29 @@ def testVocabularyBatching(self):
self.assertEquals(len(data['results']), 10)
self.assertEquals(data['total'], amount)

+ def testVocabularyEncoding(self):
+ """The vocabulary should not return the binary encoded token
+ ("N=C3=A5=C3=B8=C3=AF"), but instead the value as the id in the result
+ set. Fixes an encoding problem. See:
+ https://github.com/plone/Products.CMFPlone/issues/650
+ """
+ test_val = u'Nåøï'
+
+ def test_entities_and_unicode(self):
+ orig = '<p>(KU&nbsp;Loket) Officiële inschrijvingen </p>'
+ data = self.pt.convertTo(target_mimetype='text/x-html-safe', orig=orig)
+ self.assertEqual(data.getData(), orig)
+ self.portal.invokeFactory('Document', id="page", title="page")
+ self.portal.page.subject = (test_val,)
+ self.portal.page.reindexObject(idxs=['Subject'])
+
+ self.request.form['name'] = 'plone.app.vocabularies.Keywords'
+ results = getMultiAdapter(
+ (self.portal, self.request),
+ name='getVocabulary'
+ )()
+ results = json.loads(results)
+ result = results['results'][0]
+
+ self.assertEquals(result['text'], test_val)
+ self.assertEquals(result['id'], test_val)
+
class WordTransformsTest(ATSiteTestCase):

def afterSetUp(self):
diff --git a/Products/PortalTransforms/transforms/safe_html.py b/Products/PortalTransforms/transforms/safe_html.py
index e5e243c..8fed210 100644
--- a/Products/PortalTransforms/transforms/safe_html.py
+++ b/Products/PortalTransforms/transforms/safe_html.py
@@ -2534,9 +2534,9 @@ def unknown_starttag(self, tag, attrs):
pass

def unknown_endtag(self, tag):
+ self.inside_script = False
if tag in self.nasty and not tag in self.valid:
self.suppress = False
- self.inside_script = False
if self.suppress:
return
if safeToInt(self.valid.get(tag)):
def testVocabularyUnauthorized(self):
setRoles(self.portal, TEST_USER_ID, [])
view = VocabularyView(self.portal, self.request)


Repository: Products.PortalTransforms
Repository: plone.app.content


Branch: refs/heads/master
Date: 2015-06-24T12:01:28+02:00
Author: Godefroid Chapelle (gotcha) <gotcha@bubblenet.be>
Commit: https://github.com/plone/Products.PortalTransforms/commit/f2f3721c236611c0145dc7213eb611ccca436ff4
Date: 2015-06-25T10:57:01+02:00
Author: Johannes Raggam (thet) <raggam-nl@adm.at>
Commit: https://github.com/plone/plone.app.content/commit/62bbf28c17ab89c55f8b26c1844404b781aef712

tune manifest
Merge pull request #34 from plone/thet-vocabularyencoding

Files changed:
M MANIFEST.in

diff --git a/MANIFEST.in b/MANIFEST.in
index f220fc4..6442174 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,5 @@
include *
+exclude .installed.cfg

recursive-include docs *
recursive-include Products *


Repository: Products.PortalTransforms


Branch: refs/heads/master
Date: 2015-06-24T12:01:42+02:00
Author: Godefroid Chapelle (gotcha) <gotcha@bubblenet.be>
Commit: https://github.com/plone/Products.PortalTransforms/commit/021a27c72864dd43605f0682682646d15e8528f2

Preparing release 2.1.7
Fix encoding problems with Mockup Select2 widget

Files changed:
M CHANGES.rst
M setup.py
M plone/app/content/browser/vocabulary.py
M plone/app/content/tests/test_widgets.py

diff --git a/CHANGES.rst b/CHANGES.rst
index bc9c368..87bc302 100644
index 9e9d820..7fca280 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,7 +1,7 @@
Changelog
=========

-2.1.7 (unreleased)
+2.1.7 (2015-06-24)
@@ -4,7 +4,12 @@ Changelog
3.0.7 (unreleased)
------------------

- fix safe_html with entities after a <script> tag
diff --git a/setup.py b/setup.py
index 705ac4d..0df2a04 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages
-- Nothing changed yet.
+- Let ``@@getVocabulary`` return the vocabulary's value instead of the token
+ for the id in the result set. The token is binary encoded and leads to
+ encoding errors when selecting a value with non-ASCII data from vocabulary
+ list in a select2 based widget.
+ Fixes: https://github.com/plone/Products.CMFPlone/issues/650
+ [thet]

-version = '2.1.7.dev0'
+version = '2.1.7'

setup(name='Products.PortalTransforms',
version=version,


Repository: Products.PortalTransforms


Branch: refs/heads/master
Date: 2015-06-24T12:02:09+02:00
Author: Godefroid Chapelle (gotcha) <gotcha@bubblenet.be>
Commit: https://github.com/plone/Products.PortalTransforms/commit/2db3e5d663e878f7e4663b2bd5f63924d7f0d6ea

Back to development: 2.1.8

Files changed:
M CHANGES.rst
M setup.py

diff --git a/CHANGES.rst b/CHANGES.rst
index 87bc302..d65fbc1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,12 @@
Changelog
=========
3.0.6 (2015-06-05)
diff --git a/plone/app/content/browser/vocabulary.py b/plone/app/content/browser/vocabulary.py
index 9754fc3..9108a20 100644
--- a/plone/app/content/browser/vocabulary.py
+++ b/plone/app/content/browser/vocabulary.py
@@ -153,7 +153,7 @@ def __call__(self):
items.append(item)
else:
for item in results:
- items.append({'id': item.token, 'text': item.title})
+ items.append({'id': item.value, 'text': item.title})

+2.1.8 (unreleased)
+------------------
if total == 0:
total = len(items)
diff --git a/plone/app/content/tests/test_widgets.py b/plone/app/content/tests/test_widgets.py
index be32820..ba4a7b6 100644
--- a/plone/app/content/tests/test_widgets.py
+++ b/plone/app/content/tests/test_widgets.py
@@ -15,6 +15,7 @@
from plone.app.widgets.testing import ExampleVocabulary
from plone.app.widgets.testing import PLONEAPPWIDGETS_INTEGRATION_TESTING
from plone.app.widgets.testing import TestRequest
+from zope.component import getMultiAdapter
from zope.component import provideAdapter
from zope.component import provideUtility
from zope.component.globalregistry import base
@@ -175,6 +176,29 @@ def testVocabularyBatching(self):
self.assertEquals(len(data['results']), 10)
self.assertEquals(data['total'], amount)

+ def testVocabularyEncoding(self):
+ """The vocabulary should not return the binary encoded token
+ ("N=C3=A5=C3=B8=C3=AF"), but instead the value as the id in the result
+ set. Fixes an encoding problem. See:
+ https://github.com/plone/Products.CMFPlone/issues/650
+ """
+ test_val = u'Nåøï'
+
+- Nothing changed yet.
+ self.portal.invokeFactory('Document', id="page", title="page")
+ self.portal.page.subject = (test_val,)
+ self.portal.page.reindexObject(idxs=['Subject'])
+
+ self.request.form['name'] = 'plone.app.vocabularies.Keywords'
+ results = getMultiAdapter(
+ (self.portal, self.request),
+ name='getVocabulary'
+ )()
+ results = json.loads(results)
+ result = results['results'][0]
+
2.1.7 (2015-06-24)
------------------

diff --git a/setup.py b/setup.py
index 0df2a04..8c7cc42 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

-version = '2.1.7'
+version = '2.1.8.dev0'

setup(name='Products.PortalTransforms',
version=version,
+ self.assertEquals(result['text'], test_val)
+ self.assertEquals(result['id'], test_val)
+
def testVocabularyUnauthorized(self):
setRoles(self.portal, TEST_USER_ID, [])
view = VocabularyView(self.portal, self.request)


0 comments on commit c2ab901

Please sign in to comment.