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 --- pydyf/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'pydyf') 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'>' -- cgit v1.2.3