Fix commands where we're unable to set options to empty values because of wrong conditions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 413
- Avg merge
- 5d 6h
- Merged PRs (30d)
- 21
Description
For certain commands, setting an option to an empty value will not take care of resetting a value in MS365. This is caused by badly written conditions.
take the following example from spo list set
private mapRequestBody(options: Options): any {
const requestBody: any = {};
if (options.newTitle) {
requestBody.Title = options.newTitle;
}
if (options.description) {
requestBody.Description = options.description;
}
//...
}
This function builds a request object to post to SharePoint. The problem is that using an empty string for description will cause the runtime to skip the if-statement.
That's because an empty string is considered a falsy value in JavaScript, when used in a condition.
So if options.description is an empty string, if (options.description) { } will be evaluated to false.
The right check in this case should be an explicit undefined check:
if (options.description !== undefined) { }
or
if (typeof options.description !== "undefined") { }
Originally posted by @martinlingstuyl in https://github.com/pnp/cli-microsoft365/issues/3718#issuecomment-1260830957
Commands
This impacts primarily set commands, where a user would set something to empty. The situation occurs as far as I can see in the following commands (but there might be more):
- spo list set
- spo customaction set
- teams channel set
- teams team set
- todo task set
- aad o365group set
- aad user set
- graph schemaextension set
- spo web set
- spo site set
- spo sitedesign set
- spo sitescript set
- planner plan set
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the command implementations for spo list set and the other listed set commands, then inspect their request-mapping entry points such as mapRequestBody. Verify each option condition handles an empty value as described, and confirm that all listed commands can reset the corresponding Microsoft 365 value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100