[ X ] Bug
[ ] Enhancement
Using the spo login command with username and password should result in a successfull login when the password has a double quotes.
When using a double quote in the password the spo login command fails
$pwd = ')"ww",}'
$username = '[email protected]'
$adminUrl = 'https://tenant-admin.sharepoint.com'
o365 spo login $adminUrl -u $username -p $pwd -t password --verbose
The command above throws the following error:
"ww" was unexpected at this time.
"C:\Users\user\AppData\Roaming\npm\\node.exe" "C:\Users\user\AppData\Roaming\npm\\node_modules\@pnp\office365-cli\dist\index.js" spo login https://tenant-admin.sharepoint.com -u [email protected] -p )"ww",} -t password --verbose
I tried escaping special characters but nothing seems to work. Could you please advise?
Thanks in advance.
Hi @agtenr, thanks for reporting this! Could you please specify what Operating System (Windows 10, Linux etc.) are you using? Also what command line program (cmd, PowerShell or other) are you using to execute the script? I am asking since different command line programs escape quotes differently.
Thanks!
Hi @VelinGeorgiev , I am using windows 10. I tried it in PowerShell and cmd but both have the same behaviour.
KR, Robin
Thanks for the details @agtenr. We'll have a look at it asap.
OK, so it seems like it's not related to the CLI itself but rather how PowerShell passes variables to node executables. Following it's what's working for me:
$pwd = '''")""ww"",}"'''
$username = '[email protected]'
$adminUrl = 'https://tenant-admin.sharepoint.com'
o365 spo login $adminUrl -u $username -p "--%" $pwd -t password --verbose
Here is why:
Using --% disables PowerShell processing everything that follows. If you did --% $pwd without quotes surrounding --%, you would end up passing $pwd literally as password rather than its value. By surrounding --% with double quotes, $pwd gets expanded and then its value is passed literally on, which brings to another problem.
Once $pwd gets expanded, o365 is translated to "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\@pnp\office365-cli\dist\index.js" spo login ... (or its equivalent) and passed to cmd.exe which then parses arguments. At that stage the literal value of $pwd needs to be properly escaped for cmd. So )"ww",} needs to become '")""ww"",}"'. Since this value is defined in PowerShell as a variable, all quotes need to be escaped first so that in the end you will end up with a proper string.
It's a lot of escaping but again, it's not specific to the CLI and something you'd encounter with any other node-based executable ran from PowerShell.
Hope this helps 馃憤
I tested and it seems to work that way. Thanks a lot for the quick response and explanation.
Happy to help! Glad to hear it's working!