Skip to content

Bug report: 'file list' command throws an exception when 'folderUrl' ends with a '/' #4658

@martinlingstuyl

Description

@martinlingstuyl

Description

The following script throws an error:

m365 file list --folderUrl "/sites/somesite/Shared Documents/" --webUrl "https://contoso.sharepoint.com/sites/somesite" --verbose

While excluding the trailing slash does work:

m365 file list --folderUrl "/sites/somesite/Shared Documents" --webUrl "https://contoso.sharepoint.com/sites/somesite" --verbose

CLI for Microsoft 365 version

6.4 (next)

nodejs version

16.15.0

Operating system (environment)

Windows

Shell

PowerShell

Additional Info

The error is caused by the url manipulation here. documentLibraryRelativeFolderUrl probably contains /. Which causes the URL to include root: instead of the expected root.

const documentLibraryRelativeFolderUrl: string = folderUrl.href.replace(new RegExp(documentLibrary.webUrl as string, 'i'), '');
const requestOptions: CliRequestOptions = {
  url: `${this.resource}/v1.0/drives/${documentLibrary.id}/root${documentLibraryRelativeFolderUrl.length > 0 ? `:${documentLibraryRelativeFolderUrl}` : ''}?$select=id`,
  headers: {
    accept: 'application/json;odata.metadata=none'
  },
  responseType: 'json'
};

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions