Skip to content

Commit a1b41fa

Browse files
committed
Fixed minor issues
1 parent dcbeba1 commit a1b41fa

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

codext/__common__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ def __rank(prev_input, input, prev_encoding, encodings, heuristic=False, extende
13081308
t = __score(prev_input, input, prev_encoding, e, codec, heuristic, extended)
13091309
if t:
13101310
ranking[e] = t
1311-
for encoding, result in sorted(ranking.items(), key=lambda x: -x[1][0]):
1311+
for encoding, result in sorted(ranking.items(), key=lambda x: (-x[1][0], x[0])):
13121312
yield result if yield_score else result[1], encoding
13131313

13141314

@@ -1403,7 +1403,7 @@ def __score(prev_input, input, prev_encoding, encoding, codec, heuristic=False,
14031403
entr = entr(obj.entropy)
14041404
if entr is not None:
14051405
# use a quadratic heuristic to compute a weight for the entropy delta, aligned on (256,.2) and (512,1)
1406-
d_entr = min(3.04575e-06 * obj.len**2 + .000394 * obj.len, 1) * abs(entr - entropy(new_input))
1406+
d_entr = min(3.04575e-06 * obj.len**2 + .000394 * obj.len, 1) * abs(entr - obj.entropy)
14071407
if d_entr <= .5:
14081408
s += .5 - d_entr
14091409
# finally, if relevant, apply a custom bonus (e.g. when a regex pattern is matched)

tests/test_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def test_rank_input(self):
211211
ENC = codext.encode(STR, "base64")
212212
self.assertTrue(len(codext.rank(ENC)) > 20)
213213
self.assertEqual(len(codext.rank(ENC, limit=20)), 20)
214-
self.assertIn(codext.rank(ENC, exclude=["rot"])[0][1], ["base64", "base64-url"])
214+
self.assertIn(codext.rank(ENC, exclude=["rot"])[0][1], ["base64", "base64-url", "base64-inv"])
215215
self.assertEqual(codext.rank(ENC, include="base")[0][0][1], STR)
216216
self.assertEqual(codext.rank(ENC, include=["base"])[0][0][1], STR)
217217
self.assertIsNotNone(codext.rank(ENC, include=["base"], exclude=["does_not_exist"])[0][0][1], STR)

0 commit comments

Comments
 (0)