Ensure proper quoting for various operators · python-hyper/uritemplate@9a3307e · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 9a3307e

Browse files
committed
Ensure proper quoting for various operators
With a small refactor, and some better logic and naming, we can easily fix the issue of double escaping %s in strings they should not be escaped in. Closes #99
1 parent 0ba02f6 commit 9a3307e

File tree

3 files changed

+217
-113
lines changed

3 files changed

+217
-113
lines changed

tests/test_from_fixtures.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ def _get_test(
4444
) -> t.Tuple[ExampleVariables, ExampleTemplatesAndResults]:
4545
test = t.cast(ExampleWithVariables, self.examples.get(section, {}))
4646
return (
47-
t.cast(ExampleVariables, test.get("variables", {})),
48-
t.cast(ExampleTemplatesAndResults, test.get("testcases", [])),
47+
test.get("variables", {}),
48+
test.get("testcases", []),
4949
)
5050

5151
def _test(self, testname: str) -> None:
5252
variables, testcases = self._get_test(testname)
5353
for template, expected in testcases:
5454
expected_templates = expected_set(expected)
5555
expanded = uritemplate.expand(template, variables)
56-
assert expanded in expected_templates
56+
assert expanded in expected_templates, ( # nosec
57+
f"expanded {template!r} with {variables!r} "
58+
f"and got {expanded!r} but expected one of "
59+
f"{expected_templates!r}"
60+
)
5761

5862

5963
class TestSpecExamples(FixtureMixin):

tests/test_uritemplate.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_semi_path_expansion(self) -> None:
562562
self.assertEqual(
563563
v._semi_path_expansion("foo", None, False, False), None
564564
)
565-
t.variables[0].operator = "?"
565+
t.variables[0].operator = variable.Operator.form_style_query
566566
self.assertEqual(
567567
v._semi_path_expansion("foo", ["bar", "bogus"], True, False),
568568
"foo=bar&foo=bogus",
@@ -588,50 +588,6 @@ def test_no_mutate(self) -> None:
588588
self.assertEqual(args, {})
589589

590590

591-
class TestURIVariable(unittest.TestCase):
592-
def setUp(self) -> None:
593-
self.v = variable.URIVariable("{foo}")
594-
595-
def test_post_parse(self) -> None:
596-
v = self.v
597-
self.assertEqual(v.join_str, ",")
598-
self.assertEqual(v.operator, "")
599-
self.assertEqual(v.safe, "")
600-
self.assertEqual(v.start, "")
601-
602-
def test_post_parse_plus(self) -> None:
603-
v = self.v
604-
v.operator = "+"
605-
v.post_parse()
606-
self.assertEqual(v.join_str, ",")
607-
self.assertEqual(v.safe, variable.URIVariable.reserved)
608-
self.assertEqual(v.start, "")
609-
610-
def test_post_parse_octothorpe(self) -> None:
611-
v = self.v
612-
v.operator = "#"
613-
v.post_parse()
614-
self.assertEqual(v.join_str, ",")
615-
self.assertEqual(v.safe, variable.URIVariable.reserved)
616-
self.assertEqual(v.start, "#")
617-
618-
def test_post_parse_question(self) -> None:
619-
v = self.v
620-
v.operator = "?"
621-
v.post_parse()
622-
self.assertEqual(v.join_str, "&")
623-
self.assertEqual(v.safe, "")
624-
self.assertEqual(v.start, "?")
625-
626-
def test_post_parse_ampersand(self) -> None:
627-
v = self.v
628-
v.operator = "&"
629-
v.post_parse()
630-
self.assertEqual(v.join_str, "&")
631-
self.assertEqual(v.safe, "")
632-
self.assertEqual(v.start, "&")
633-
634-
635591
class TestVariableModule(unittest.TestCase):
636592
def test_is_list_of_tuples(self) -> None:
637593
a_list = [(1, 2), (3, 4)]

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.