From 0202f7a33e1043d654826d1a29ef950fe2f69b78 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Nov 2021 04:31:35 +0100 Subject: Merging upstream version 0.1.2. Signed-off-by: Daniel Baumann --- PKG-INFO | 2 +- docs/changelog.rst | 38 ++++++++++++++++++++++++++++++++++++++ pydyf/__init__.py | 10 ++++++++-- setup.py | 2 +- tests/test_pydyf.py | 3 +++ 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/PKG-INFO b/PKG-INFO index fe00eef..d6c6777 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pydyf -Version: 0.1.1 +Version: 0.1.2 Summary: A low-level PDF generator. Keywords: pdf,generator Author-email: CourtBouillon diff --git a/docs/changelog.rst b/docs/changelog.rst index cbebc90..acbf3c3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,44 @@ Changelog ========= +Version 0.1.2 +------------- + +Released on 2021-10-30. + +Bug fixes: + +* `#9 `_: + Implement escaping for Strings + +Contributors: + +* Guillaume Ayoub +* Rian McGuire + +Backers and sponsors: + +* Grip Angebotssoftware +* SimonSoft +* Menutech +* Manuel Barkhau +* Simon Sapin +* KontextWork +* René Fritz +* Maykin Media +* NCC Group +* Crisp BV +* Des images et des mots +* Andreas Zettl +* Nathalie Gutton +* Tom Pohl +* Moritz Mahringer +* Florian Demmer +* Yanal-Yvez Fargialla +* G. Allard +* Gábor + + Version 0.1.1 ------------- diff --git a/pydyf/__init__.py b/pydyf/__init__.py index 4ad0bde..05dccf6 100755 --- a/pydyf/__init__.py +++ b/pydyf/__init__.py @@ -3,10 +3,11 @@ A low-level PDF generator. """ +import re import zlib from codecs import BOM_UTF16_BE -VERSION = __version__ = '0.1.1' +VERSION = __version__ = '0.1.2' def _to_bytes(item): @@ -375,7 +376,12 @@ class String(Object): @property def data(self): try: - return b'(' + _to_bytes(self.string) + b')' + # "A literal string is written as an arbitrary number of characters + # enclosed in parentheses. Any characters may appear in a string + # except unbalanced parentheses and the backslash, which must be + # treated specially." + escaped = re.sub(rb'([\\\(\)])', rb'\\\1', _to_bytes(self.string)) + return b'(' + escaped + b')' except UnicodeEncodeError: encoded = BOM_UTF16_BE + str(self.string).encode('utf-16-be') return b'<' + encoded.hex().encode() + b'>' diff --git a/setup.py b/setup.py index 45b7533..40b63c0 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ extras_require = \ 'pillow']} setup(name='pydyf', - version='0.1.1', + version='0.1.2', description='A low-level PDF generator.', author=None, author_email='CourtBouillon ', diff --git a/tests/test_pydyf.py b/tests/test_pydyf.py index 87d9763..1e758a5 100644 --- a/tests/test_pydyf.py +++ b/tests/test_pydyf.py @@ -706,3 +706,6 @@ def test_string_encoding(): assert pydyf.String('abc').data == b'(abc)' assert pydyf.String('déf').data == b'' assert pydyf.String('♡').data == b'' + assert pydyf.String('\\abc').data == b'(\\\\abc)' + assert pydyf.String('abc(').data == b'(abc\\()' + assert pydyf.String('ab)c').data == b'(ab\\)c)' -- cgit v1.2.3