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

Unescape header names in addition to values #49

Merged
merged 2 commits into from
Aug 14, 2015
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
24 changes: 23 additions & 1 deletion stomp/test/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,26 @@ def test_convert_frame_to_lines(self):
if sys.hexversion >= 0x03000000:
self.assertEquals(bytearray('SEND\nheader1:value1\n\nthis is the body\x00', 'ascii'), s)
else:
self.assertEquals('SEND\nheader1:value1\n\nthis is the body\x00', s)
self.assertEquals('SEND\nheader1:value1\n\nthis is the body\x00', s)

def test_parse_headers(self):
lines = [
r'h1:foo\c\\bar ',
r'h1:2nd h1 ignored -- not a must, but allowed and that is how we behave ATM',
r'h\c2:baz\r\nquux',
]
self.assertEquals(
{'h1': r'foo:\bar ', 'h:2': 'baz\r\nquux'}, parse_headers(lines))

def test_calculate_heartbeats(self):
chb = (3000, 5000)
shb = map(str, reversed(chb))
self.assertEquals((3000, 5000), calculate_heartbeats(shb, chb))
shb = ('6000', '2000')
self.assertEquals((3000, 6000), calculate_heartbeats(shb, chb))
shb = ('0', '0')
self.assertEquals((0, 0), calculate_heartbeats(shb, chb))
shb = ('10000', '0')
self.assertEquals((0, 10000), calculate_heartbeats(shb, chb))
chb = (0, 0)
self.assertEquals((0, 0), calculate_heartbeats(shb, chb))
5 changes: 3 additions & 2 deletions stomp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def parse_headers(lines, offset=0):
header_match = HEADER_LINE_RE.match(header_line)
if header_match:
key = header_match.group('key')
key = key.replace('\\n', '\n').replace('\\r', '\r').replace('\\\\', '\\').replace('\\c', ':')
if key not in headers:
value = header_match.group('value')
value = value.replace('\\n', '\n').replace('\\r', '\r').replace('\\\\', '\\').replace('\\c', ':')
Expand Down Expand Up @@ -156,9 +157,9 @@ def calculate_heartbeats(shb, chb):
x = 0
y = 0
if cx != 0 and sy != '0':
x = max(cx, int(sx))
x = max(cx, int(sy))
if cy != 0 and sx != '0':
y = max(cy, int(sy))
y = max(cy, int(sx))
return (x, y)


Expand Down