-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix added because somehow the $server variable contained a space... #17
base: master
Are you sure you want to change the base?
Conversation
…een the server name and port, which would cause conn.Open to hang and terminate with an error.
@nathanhere thanks. Can you explain why the space was there to begin with? Is this value being provided by another application? I assume you're trying to handle the edge-case that... $server = "foo 1433"
# instead of...
$server = "foo,1433" |
Note, this will also have the side-effect of putting commas at the end of strings... $server = "foo "
# would become...
$server = "foo,," |
Happy to provide a bit more detail to the environment I used to run this (Note the caveat that specifying port 1433 isn't required for this script, but it's my practice due to some cli commands requiring it explicitly, like In a MacOS I'm using a Windows port of Powershell within the terminal, which connects to a MS SQL Server 2017 Docker container. I found that when I ran the command:
I kept getting this error:
Prior to the main script body running, upon printing the variable Due to the newness of this script to me (and powershell itself, especially powershell in a MacOS environment), I was unaware of an edge case (from user input) would cause If you're able to replicate this on a MacOS with the Windows port of Powershell, let me know if you observe the same issue. And thanks for providing this script! |
I bet PS is automagically treating the comma as an array type, then the spaces are inserted when |
Yep... Check out this question... https://stackoverflow.com/a/11990733/3196753 Let's assume others will make this same mistake and check for array. I think it'll be cleaner and more scalable. |
Reproduced. Weird. Even stranger, I'm fine with this PR so as long as we sanitize the end of the hostname using For example: ./GetMsSqlDump.ps1 -server "localhost "
# ... would change to
./GetMsSqlDump.ps1 -server "localhost,,," I've tested the spaces after hostname, and the script works just fine, so
So add the trim logic, a better code comment, and I'd be happy to merge. For code comment, I'd recommend changing it to something like this: # Handle unquoted $server translating commas to spaces |
between the server name and port, which would cause
conn.Open
to hang and terminate with an error.