RamblingCookieMonster / RabbitMQTools

PowerShell module containing cmdlets to manage RabbitMQ.
http://ramblingcookiemonster.github.io/RabbitMQ-Intro/
MIT License
31 stars 22 forks source link

Encode spaces in names as '%20' intead of '+' #42

Open stawr93 opened 5 years ago

stawr93 commented 5 years ago

If your queue (or exchange) name contains some space chars, any operations you want to do with it will end up with an error like this:

Invoke-RestMethod : {"error":"Object Not Found","reason":"Not Found"}
At C:\Program Files\WindowsPowerShell\Modules\RabbitMQTools\1.5\Public\Remove-RabbitMQQueue.ps1:94 char:17
+ ...             $result = Invoke-RestMethod $url -Credential $Credentials ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Invoke-RestMethod : {"error":"Object Not Found","reason":"Not Found"}
At C:\Program Files\WindowsPowerShell\Modules\RabbitMQTools\1.5\Public\Remove-RabbitMQQueue.ps1:94 char:17
+ ...             $result = Invoke-RestMethod $url -Credential $Credentials ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

This caused by incorrect encoding url: RMQ expects smth like: http://localhost:15672/api/queues/%2F/API%2C%20API

But actual url generated by script is: http://localhost:15672/api/queues/%2f/API%2c+API

RamblingCookieMonster commented 5 years ago

Hiyo!

Sorry for the wait, finally had time to go through PRs : ) This works for me if no one has any issues with it - Are there any cases where the inverse occurs? i.e. a string going through [System.Uri]::EscapeDataString producing something this API doesn't like?

Barring cases like that, I'm happy to merge this! Will plan on merging it in a week or two if I don't hear of any issues - can always revert, or add a switch to allow swapping those methods as needed.

Cheers!