paraparser fix contributed by ravi prakash giri <raviprakashgiri@gmail.com>; version --> 3.5.31
authorrobin
Sat, 19 Oct 2019 09:10:20 +0100
changeset 4545 b117091a73c2
parent 4544 f8ec5d88933b
child 4546 b52a51448518
paraparser fix contributed by ravi prakash giri <raviprakashgiri@gmail.com>; version --> 3.5.31
CHANGES.md
src/reportlab/__init__.py
src/reportlab/platypus/paraparser.py
tests/test_platypus_paragraphs.py
--- a/CHANGES.md	Thu Oct 17 10:11:56 2019 +0100
+++ b/CHANGES.md	Sat Oct 19 09:10:20 2019 +0100
@@ -11,6 +11,10 @@
 The contributors lists are in no order and apologies to those accidentally not
 mentioned. If we missed you, please let us know!
 
+RELEASE 3.5.31	15/10/2019
+--------------------------
+	* paraparser fix contributed by ravi prakash giri <raviprakashgiri@gmail.com>
+
 RELEASE 3.5.30	15/10/2019
 --------------------------
 	* better support for candlestick charts using smartGetItem
--- a/src/reportlab/__init__.py	Thu Oct 17 10:11:56 2019 +0100
+++ b/src/reportlab/__init__.py	Sat Oct 19 09:10:20 2019 +0100
@@ -1,9 +1,9 @@
 #Copyright ReportLab Europe Ltd. 2000-2018
 #see license.txt for license details
 __doc__="""The Reportlab PDF generation library."""
-Version = "3.5.30"
+Version = "3.5.31"
 __version__=Version
-__date__='20191015'
+__date__='20191019'
 
 import sys, os
 
--- a/src/reportlab/platypus/paraparser.py	Thu Oct 17 10:11:56 2019 +0100
+++ b/src/reportlab/platypus/paraparser.py	Sat Oct 19 09:10:20 2019 +0100
@@ -2809,7 +2809,11 @@
                 v = '\0'
         elif 'code' in attr:
             try:
-                v = int(eval(attr['code']))
+                v = attr['code'].lower()
+                if v.startswith('0x'):
+                    v = int(v,16)
+                else:
+                    v = int(v,0)    #treat as a python literal would be
                 v = chr(v) if isPy3 else unichr(v)
             except:
                 self._syntax_error('<unichar/> invalid code attribute %s' % ascii(attr['code']))
--- a/tests/test_platypus_paragraphs.py	Thu Oct 17 10:11:56 2019 +0100
+++ b/tests/test_platypus_paragraphs.py	Sat Oct 19 09:10:20 2019 +0100
@@ -7,6 +7,7 @@
 setOutDir(__name__)
 import sys, os, unittest
 from operator import truth
+from reportlab.pdfgen.canvas import Canvas
 from reportlab.pdfbase.pdfmetrics import stringWidth, registerFont, registerFontFamily
 from reportlab.pdfbase.ttfonts import TTFont
 from reportlab.platypus.paraparser import ParaParser
@@ -108,7 +109,6 @@
 
     def test3(self):
         '''compare CJK splitting in some edge cases'''
-        from reportlab.pdfgen.canvas import Canvas
         from reportlab.platypus.paragraph import Paragraph
         from reportlab.lib.styles import ParagraphStyle
         from reportlab.pdfbase import pdfmetrics
@@ -503,7 +503,6 @@
         """test that justified paragraphs with </br>last line split properly
         bug reported by Niharika Singh <nsingh@shoobx.com>
         """
-        from reportlab.pdfgen.canvas import Canvas
         measures = []
         def _odW(canv,name,label):
             measures.append((label,canv._curr_tx_info['cur_x']))
@@ -541,6 +540,12 @@
         canv.save()
         self.assertEqual(M0,measures,"difference detected in justified split Paragraph rendering")
 
+    def test_unicharCodeSafety(self):
+        """test a bug reported by ravi prakash giri <raviprakashgiri@gmail.com>"""
+        normal = getSampleStyleSheet()['BodyText']
+        self.assertRaises(Exception,Paragraph,
+                """<unichar code="open('/tmp/test.txt','w').write('Hello from unichar')"/>""",
+                normal)
 
 class TwoFrameDocTemplate(BaseDocTemplate):
     "Define a simple document with two frames per page."
@@ -682,7 +687,6 @@
         bt.fontSize = 10
         bt.leading = 12
         bt.alignment = TA_JUSTIFY
-        from reportlab.pdfgen.canvas import Canvas
         canv = Canvas(outputfile('test_platypus_paragraphs_hyphenations.pdf'))
         x = 72
         y = canv._pagesize[1] - 72