Skip to content

Commit

Permalink
Order DATERANGE x-<client-attr>s predictably
Browse files Browse the repository at this point in the history
  • Loading branch information
davemevans authored Apr 25, 2020
1 parent b071688 commit 329d093
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion m3u8/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,8 @@ def dumps(self):
if (self.end_on_next):
daterange.append('END-ON-NEXT=' + self.end_on_next)

for attr, value in self.x_client_attrs:
# client attributes sorted alphabetically output order is predictable
for attr, value in sorted(self.x_client_attrs):
daterange.append('%s=%s' % (
denormalize_attribute(attr),
value
Expand Down
4 changes: 3 additions & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,9 @@ def test_add_daterange():
def test_daterange_simple():
obj = m3u8.M3U8(playlists.DATERANGE_SIMPLE_PLAYLIST)

expected = '#EXT-X-DATERANGE:ID="ad3",START-DATE="2016-06-13T11:15:00Z",DURATION=20,X-AD-URL="http://ads.example.com/beacon3",X-AD-ID="1234"'
# note that x-<client-attribute>s are explicitly alphabetically ordered
# when dumped for predictability, so line below is different from input
expected = '#EXT-X-DATERANGE:ID="ad3",START-DATE="2016-06-13T11:15:00Z",DURATION=20,X-AD-ID="1234",X-AD-URL="http://ads.example.com/beacon3"'
result = obj.dumps()

assert expected in result
Expand Down

0 comments on commit 329d093

Please sign in to comment.