1+ Import-Module $PSScriptRoot \.. - Force
2+
3+ Describe ' ConvertFrom-UrlQueryString functionality' - Tags Unit {
4+ InModuleScope UrlQueryStringParser {
5+ BeforeAll {
6+ $complexExampleQueryString = " ?foo=bar&oogy&array=one&baz=quux&array=two&boogy&array=three&empty=&array=four&last"
7+ }
8+
9+ It ' Parses simple query string correctly' {
10+ $qs = ' ?a=1&b=two&c=3'
11+ $result = ConvertFrom-UrlQueryString - QueryString $qs
12+
13+ $result.Count | Should - Be 3
14+ $result [' a' ] | Should - Be ' 1'
15+ $result [' b' ] | Should - Be ' two'
16+ $result [' c' ] | Should - Be ' 3'
17+ }
18+
19+ It ' Handles URL encoded values and repeated keys' {
20+ $qs = ' name=John%20Doe&age=30&name=Jane'
21+ $result = ConvertFrom-UrlQueryString - QueryString $qs
22+
23+ $result [' name' ].Count | Should - Be 2
24+ $result [' name' ] | Should - Contain ' John Doe'
25+ $result [' name' ] | Should - Contain ' Jane'
26+ $result [' age' ] | Should - Be ' 30'
27+ }
28+
29+ It ' Returns zero-count hashtable for empty string' {
30+ (ConvertFrom-UrlQueryString " " ).Keys.Count | Should - Be 0
31+ }
32+
33+ It ' Converts from pseudo-empty querystring (just "?") to empty dict' {
34+ (ConvertFrom-UrlQueryString " ?" ).Keys.Count | Should - Be 0
35+ }
36+
37+ It ' Converts from from simple single-entry querystring to single-entry dict' {
38+ (ConvertFrom-UrlQueryString " foo=bar" )[" foo" ] | Should - Be " bar"
39+ }
40+
41+ It ' Converts from from simple single-entry querystring with ? prefix to single-entry dict' {
42+ (ConvertFrom-UrlQueryString " ?foo=bar" )[" foo" ] | Should - Be " bar"
43+ }
44+
45+ It ' Converts valueless entries with no = to $true' {
46+ (ConvertFrom-UrlQueryString " foo" )[" foo" ] | Should - Be $true
47+ }
48+
49+ It ' Converts valueless entries with = by dropping them' {
50+ (ConvertFrom-UrlQueryString " foo=" )[" foo" ].Length | Should - Be 0
51+ }
52+
53+ It ' Converts a complex example querystring while preserving the order of the keys' {
54+ $result = ConvertFrom-UrlQueryString $complexExampleQueryString
55+ $result.Keys -join " ," | Should - Be " foo,oogy,array,baz,boogy,empty,last"
56+ }
57+
58+ It ' Converts repeated keys into arrays while preserving value-order' {
59+ $result = ConvertFrom-UrlQueryString $complexExampleQueryString
60+ $result [' array' ] -join " ," | Should - Be " one,two,three,four"
61+ }
62+
63+ It ' Returns a case-insensitive dict' {
64+ $result = ConvertFrom-UrlQueryString $complexExampleQueryString
65+ { $result [' ArRaY' ] } | Should -Not - Throw
66+ }
67+ }
68+ }
0 commit comments