summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2021-11-15 03:31:35 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2021-11-15 03:31:35 +0000
commit0202f7a33e1043d654826d1a29ef950fe2f69b78 (patch)
tree491860456d8a71d4c6dbb270a240cc0c9690e8aa
parentAdding debian version 0.1.1-1. (diff)
downloadpydyf-0202f7a33e1043d654826d1a29ef950fe2f69b78.tar.xz
pydyf-0202f7a33e1043d654826d1a29ef950fe2f69b78.zip
Merging upstream version 0.1.2.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r--PKG-INFO2
-rw-r--r--docs/changelog.rst38
-rwxr-xr-xpydyf/__init__.py10
-rw-r--r--setup.py2
-rw-r--r--tests/test_pydyf.py3
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 <contact@courtbouillon.org>
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 <https://github.com/CourtBouillon/pydyf/pull/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 <contact@courtbouillon.org>',
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'<feff006400e90066>'
assert pydyf.String('♡').data == b'<feff2661>'
+ assert pydyf.String('\\abc').data == b'(\\\\abc)'
+ assert pydyf.String('abc(').data == b'(abc\\()'
+ assert pydyf.String('ab)c').data == b'(ab\\)c)'