Skip to content

Commit 734bd85

Browse files
committed
encoding: Fix Name.to_str
1 parent 68230fb commit 734bd85

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ Master -- (latest)
99
* Improve NDNApp.route and NDNApp.express_interest to give access the
1010
original packet and signature pointers of packets.
1111
* Fix typos in the documentation.
12-
* Support more alternate URI format of Name Component (seg, off, v, t and seq)
12+
* Support more alternate URI format of Name Component (``seg``, ``off``, ``v``, ``t`` and ``seq``)
1313
* Update Python version to 3.8 and add PyPy 7.2.0 in GitHub Action.
14+
* Fix Name.to_str so its output for ``[b'\x08\x00']`` is correct.
1415

1516
0.2b1 (2019-11-20)
1617
++++++++++++++++++

src/ndn/encoding/name/Name.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ def to_str(name: NonStrictName) -> str:
8181
'/%CE%A3%CF%80%CF%85%CF%81%CE%AF%CE%B4%CF%89%CE%BD'
8282
"""
8383
name = normalize(name)
84-
return '/' + '/'.join(Component.to_str(comp) for comp in name)
84+
ret = '/' + '/'.join(Component.to_str(comp) for comp in name)
85+
if name and name[-1] == b'\x08\x00':
86+
ret += '/'
87+
return ret
8588

8689

8790
def from_bytes(buf: BinaryStr) -> FormalName:

tests/encoding/name_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def test_string_parse():
199199
assert Name.to_str(Name.from_str('/hello//world')) == '/hello//world'
200200
assert Name.to_str(Name.from_str('/hello/./world')) == '/hello/./world'
201201
assert Name.to_str(Name.from_str('/hello/../world')) == '/hello/../world'
202+
assert Name.to_str(Name.from_str('//')) == '//'
202203

203204
@staticmethod
204205
def test_compare():

0 commit comments

Comments
 (0)