cli-microsoft365: Bug report: Updating a content type property with an empty value throws an exception

Description

If I run the following command:

m365 spo contenttype set --webUrl '<url>' --id '<some-id>' --listTitle '<some-title>' --Description ''  --debug

The command throws a 400 exception.

The reason this happens is because the Description option is translated to a boolean when calling the API:

"data": {
    "Description": true
  }

Steps to reproduce

  1. Update a content type with a description
  2. Now try to empty it by running the same command with an empty value in string quotes.

Expected results

The property is emptied.

Actual results

The command crashes.

CLI for Microsoft 365 version

5.8 (next)

nodejs version

16.15.0

Operating system (environment)

Windows

Shell

PowerShell

Additional Info

This issue does not occur on bash.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 28 (28 by maintainers)

Most upvoted comments

Great finding @milanholemans and it’s weird that there’s a difference between --option '' and --option=''. I’d expect that they’re equal, but it turns out they aren’t! I wonder if it originates from minimist or the shell. Either way, let’s definitely document this because I’m sure folks will run into it.

I’m not on my PC right now, but have you also tried to use --someStringOption=""?

Not sure if I did, will try it asap!

In that case I’ll close this issue and create a new one for updating the documentation!

I wonder if it originates from minimist or the shell.

It’s the PowerShell, not minimist. That’s clear @waldekmastykarz .

So we’re agreed we’re seeing this as a valid workaround and that we don’t need to influence the args list for this ourselves?

Nice to know that this works 😃 We already have a section about the argument parsing with a dash https://pnp.github.io/cli-microsoft365/user-guide/using-cli/#values-starting-with-a-dash-

Maybe we can generalize it a bit and include the empty string argument as well.

And what about passing a null value? Or is it the same as passing an empty string?

Aw ok I see, should have read the entire thread, sorry!

Should we start adding every relevant property to the string and boolean arrays?

Where it makes sense, yes.

Should we start adding every relevant property to the string and boolean arrays?

Let’s start small and avoid trying to boil the ocean.

Also, if (options.description) { will return false for an empty script, so we’d need to adjust it to check explicitly for undefined

First thing we should try is to force these options to be treated as string by minimist and see if that solves it.