@@ -672,8 +672,11 @@ def test_expansion_ignores_none_list_items_for_all_operators(
672672 values = {"x" : ["a" , None , "b" ]}
673673 expected = {
674674 "{x}" : "a,b" ,
675+ "{x*}" : "a,b" ,
675676 "{+x}" : "a,b" ,
677+ "{+x*}" : "a,b" ,
676678 "{#x}" : "#a,b" ,
679+ "{#x*}" : "#a,b" ,
677680 "{.x}" : ".a,b" ,
678681 "{.x*}" : ".a.b" ,
679682 "{/x}" : "/a,b" ,
@@ -690,6 +693,40 @@ def test_expansion_ignores_none_list_items_for_all_operators(
690693 with self .subTest (template = template ):
691694 self .assertEqual (URITemplate (template ).expand (values ), result )
692695
696+ def test_expansion_preserves_defined_empty_and_zero_list_items (
697+ self ,
698+ ) -> None :
699+ values = {"x" : ["" , None , 0 , None , "b" ]}
700+ expected = {
701+ "{x}" : ",0,b" ,
702+ "{x*}" : ",0,b" ,
703+ "{+x}" : ",0,b" ,
704+ "{+x*}" : ",0,b" ,
705+ "{#x}" : "#,0,b" ,
706+ "{#x*}" : "#,0,b" ,
707+ "{.x}" : ".,0,b" ,
708+ "{.x*}" : "..0.b" ,
709+ "{/x}" : "/,0,b" ,
710+ "{/x*}" : "//0/b" ,
711+ "{;x}" : ";x=,0,b" ,
712+ "{;x*}" : ";x=;x=0;x=b" ,
713+ "{?x}" : "?x=,0,b" ,
714+ "{?x*}" : "?x=&x=0&x=b" ,
715+ "{&x}" : "&x=,0,b" ,
716+ "{&x*}" : "&x=&x=0&x=b" ,
717+ }
718+
719+ for template , result in expected .items ():
720+ with self .subTest (template = template ):
721+ self .assertEqual (URITemplate (template ).expand (values ), result )
722+
723+ def test_expansion_does_not_mutate_none_containing_lists (self ) -> None :
724+ values = {"x" : ["a" , None , "b" ]}
725+ for template in ("{x}" , "{.x}" , "{;x}" , "{?x}" ):
726+ with self .subTest (template = template ):
727+ URITemplate (template ).expand (values )
728+ self .assertEqual (values , {"x" : ["a" , None , "b" ]})
729+
693730
694731if __name__ == "__main__" :
695732 unittest .main ()
0 commit comments