-
Notifications
You must be signed in to change notification settings - Fork 2
Description
It looks like lists get sorted here.
AFAIU, although dictionary entries are supposed to be sorted by key:
Dictionaries are encoded as follows: d<bencoded string><bencoded element>e
The initial d and trailing e are the beginning and ending delimiters. Note that the keys must be bencoded strings. The values may be any bencoded type, including integers, strings, lists, and other dictionaries. Keys must be strings and appear in sorted order (sorted as raw strings, not alphanumerics). The strings should be compared using a binary comparison, not a culture-specific "natural" comparison.
list order is not supposed to be changed:
Lists are encoded as follows: l<bencoded values>e
The initial l and trailing e are beginning and ending delimiters. Lists may contain any bencoded type, including integers, strings, dictionaries, and even lists within other lists.
via: https://wiki.theory.org/BitTorrentSpecification#Lists and https://wiki.theory.org/BitTorrentSpecification#Dictionaries
May be tweaking one of the write tests would make sense to catch this?
diff --git a/test/bencode_test.janet b/test/bencode_test.janet
index 7791842..c5f93b7 100644
--- a/test/bencode_test.janet
+++ b/test/bencode_test.janet
@@ -353,8 +353,8 @@
(same? "l6:cheesee" bencoded)))
(test "Write list 3"
- (let [bencoded (bencode/write ["cheese" "eggs" "ham"])]
- (same? "l6:cheese4:eggs3:hame" bencoded)))
+ (let [bencoded (bencode/write ["cheese" "ham" "eggs"])]
+ (same? "l6:cheese3:ham4:eggse" bencoded)))
(test "Write Map 1"
(let [bencoded (bencode/write {})]