Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf-8 fix in unpickle #2660

Merged
merged 4 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions webapp/graphite/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class SafeUnpickler(pickle.Unpickler):
'graphite.intervals': set(['Interval', 'IntervalSet']),
}

def __init__(self, file):
super().__init__(file, encoding='utf8')

def find_class(self, module, name):
if module not in self.PICKLE_SAFE:
raise pickle.UnpicklingError('Attempting to unpickle unsafe module %s' % module)
Expand Down
13 changes: 13 additions & 0 deletions webapp/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- encoding: utf-8 -*-
import os
import socket
import pytz

from datetime import datetime
from mock import patch
from io import BytesIO

from .base import TestCase

Expand Down Expand Up @@ -119,3 +121,14 @@ def test_logtime(ok, custom=None, timer=None):
test_logtime(False)
self.assertEqual(log.info.call_count, 3)
self.assertRegexpMatches(log.info.call_args[0][0], r'test :: failed in [-.e0-9]+s')


class SafeUnpicklerTest(TestCase):

def test_load(self):
unpickler = util.unpickle()
p = b"S'test.d\\xc3\\xb8d'\np0\n."
u = unpickler.load(BytesIO(p))
x = 'test.død'

self.assertEqual(u, x)