summaryrefslogtreecommitdiff
path: root/net-misc/streamlink/files/streamlink-6.7.2-validator.patch
blob: 8dc69d62616ab591999eddea271c29ab6a916d23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
https://github.com/streamlink/streamlink/pull/5932
https://github.com/streamlink/streamlink/commit/0466622dc0bd13db972f6a00d2e2bda31ad50229

Quoting the PR:
"""
Since Python 3.11.9 / 3.12.3 / 3.13.0a6, urllib.parse.parse_qsl() now raises a TypeError
if the input is not a str, is truthy and can't be passed to memoryview(), like integers for example,
hence the test failure which previously just checked an invalid input to that validation schema.
"""

From 51c13ddd45f83384cf7800a881127ad74dec3bb8 Mon Sep 17 00:00:00 2001
From: bastimeyer <mail@bastimeyer.de>
Date: Tue, 9 Apr 2024 21:36:03 +0200
Subject: [PATCH] plugin.api.validate: check parse_qsd() input type

---
 src/streamlink/plugin/api/validate/_validators.py |  6 +++++-
 tests/test_api_validate.py                        | 11 +++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/streamlink/plugin/api/validate/_validators.py b/src/streamlink/plugin/api/validate/_validators.py
index 69135b74919..e99d305733f 100644
--- a/src/streamlink/plugin/api/validate/_validators.py
+++ b/src/streamlink/plugin/api/validate/_validators.py
@@ -651,4 +651,8 @@ def validator_parse_qsd(*args, **kwargs) -> TransformSchema:
     :raise ValidationError: On parsing error
     """
 
-    return TransformSchema(_parse_qsd, *args, **kwargs, exception=ValidationError, schema=None)
+    def parser(*_args, **_kwargs):
+        validate(AnySchema(str, bytes), _args[0])
+        return _parse_qsd(*_args, **_kwargs, exception=ValidationError, schema=None)
+
+    return TransformSchema(parser, *args, **kwargs)
diff --git a/tests/test_api_validate.py b/tests/test_api_validate.py
index ceff9bc1dde..c328116d27b 100644
--- a/tests/test_api_validate.py
+++ b/tests/test_api_validate.py
@@ -1343,13 +1343,20 @@ def test_success(self):
             validate.parse_qsd(),
             "foo=bar&foo=baz&qux=quux",
         ) == {"foo": "baz", "qux": "quux"}
+        assert validate.validate(
+            validate.parse_qsd(),
+            b"foo=bar&foo=baz&qux=quux",
+        ) == {b"foo": b"baz", b"qux": b"quux"}
 
     def test_failure(self):
         with pytest.raises(ValidationError) as cm:
             validate.validate(validate.parse_qsd(), 123)
         assert_validationerror(cm.value, """
-            ValidationError:
-              Unable to parse query string: 'int' object has no attribute 'decode' (123)
+            ValidationError(AnySchema):
+              ValidationError(type):
+                Type of 123 should be str, but is int
+              ValidationError(type):
+                Type of 123 should be bytes, but is int
         """)