diff options
| author | Tiberiu Danciu <tiberiud99@gmail.com> | 2019-08-16 20:42:12 +0300 |
|---|---|---|
| committer | Tiberiu Danciu <tiberiud99@gmail.com> | 2019-08-16 20:42:12 +0300 |
| commit | faefccc37dfe5858aaf54e158454fd0d9cbbd1c5 (patch) | |
| tree | 295c219c8856286a867afc627d04a1c405a0cc37 | |
| parent | b8b263fd9956aef078b8a5c988813c7b911ba477 (diff) | |
Fixed major flaw in parsing colors.
| -rw-r--r-- | tests/test_parse.py | 3 | ||||
| -rw-r--r-- | viewstate/parse.py | 25 |
2 files changed, 17 insertions, 11 deletions
diff --git a/tests/test_parse.py b/tests/test_parse.py index 1a2913a..e971955 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -39,6 +39,9 @@ class TestParse(object): def test_color(self): vs = ViewState(raw=b'\xff\x01\n\x91') assert vs.decode() == 'Color: Salmon' + + vs = ViewState(raw=b'\xff\x01\n\x8d\x01') + assert vs.decode() == 'Color: Red' def test_rgba(self): vs = ViewState(raw=b'\xff\x01\x09\x10\x20\x30\x40') diff --git a/viewstate/parse.py b/viewstate/parse.py index 6646c39..cae0300 100644 --- a/viewstate/parse.py +++ b/viewstate/parse.py @@ -41,15 +41,6 @@ class Const(Parser): return cls.const, remain -class Noop(Parser): - # This class is not up to specification. No value should be added to the parsed tree. - marker = 0x01 - - @staticmethod - def parse(b): - return None, b - - class NoneConst(Const): marker = 0x64 const = None @@ -310,10 +301,17 @@ class Color(Parser): "MenuHighlight", ] + color = 'Unknown' try: - return 'Color: {}'.format(color_table[b[0]]), b[1:] + color = 'Color: {}'.format(color_table[b[0]]) except IndexError: - return 'Color: Unknown', b[1:] + pass + + # If color packet ends with `\x01` + if len(b) > 1 and b[1] == 1: + return color, b[2:] + else: + return color, b[1:] class Pair(Parser): @@ -385,10 +383,15 @@ class Array(Parser): @staticmethod def parse(b): n, remain = Integer.parse(b) + if n > 400: + n, remain = Integer.parse(b) + l = [] for _ in range(n): val, remain = Parser.parse(remain) l.append(val) + if n>400: + print("lel") return l, remain |
