Skip to content

Commit

Permalink
- Decrease cookie size for copy/paste clipboard cookie (fixes #854)
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Jun 18, 2020
1 parent 528d1b4 commit 6d486ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
5.0a3 (unreleased)
------------------

- Decrease cookie size for copy/paste clipboard cookie
(`#854 <https://github.com/zopefoundation/Zope/issues/854>`_)

- Fix ``default`` keyword handling in page templates
(`#846 <https://github.com/zopefoundation/Zope/issues/846>`_)

Expand Down
10 changes: 5 additions & 5 deletions src/OFS/CopySupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
"""Copy interface
"""

import base64
import logging
import re
import tempfile
import warnings
from json import dumps
from json import loads
from urllib.parse import quote
from urllib.parse import unquote
from zlib import compress
from zlib import decompressobj

Expand Down Expand Up @@ -669,7 +668,7 @@ def _cb_encode(d):
json_bytes = dumps(d).encode('utf-8')
squashed_bytes = compress(json_bytes, 2) # -> bytes w/ useful encoding
# quote for embeding in cookie
return quote(squashed_bytes.decode('latin-1'))
return base64.encodebytes(squashed_bytes)


def _cb_decode(s, maxsize=8192):
Expand All @@ -681,8 +680,9 @@ def _cb_decode(s, maxsize=8192):
Return a list of text IDs.
"""
dec = decompressobj()
squashed = unquote(s).encode('latin-1')
data = dec.decompress(squashed, maxsize)
if isinstance(s, str):
s = s.encode('latin-1')
data = dec.decompress(base64.decodebytes(s), maxsize)
if dec.unconsumed_tail:
raise ValueError
json_bytes = data.decode('utf-8')
Expand Down

0 comments on commit 6d486ca

Please sign in to comment.