microsoft / microsoft/BCApps

[Bug]: External File Storage - SharePoint upload fails when the file name contains a colon or an apostrophe

Open
#11,143 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Approved Team: Integrations
Dominant language
AL
Stars
683
Forks
459
Avg merge
3d 26m
Merged PRs (30d)
633

Description

Describe the issue
Summary

Uploading a document attachment to an External File Storage account of type SharePoint fails when the file name contains a colon (:) or a single quote ('). Manually drag & dropping the same file into the SharePoint folder works, so the problem is in how the connector builds the API call.

Analysis of the current code

1. No sanitization at all in the connector

codeunit 4580 "Ext. SharePoint Connector Impl".CreateFile only calls SplitPath and then delegates to Ext. SharePoint Graph Helper / Ext. SharePoint REST Helper depending on the Use legacy REST API flag. Neither helper validates or sanitizes the file name (src/Apps/W1/External File Storage - SharePoint Connector/App/src/).

2. Apostrophe — real escaping bug on the legacy REST path

SharePointClientImpl.AddFileToFolder builds:

GetFolderByServerRelativeUrl('<folder>')/Files/add(url='<FileName>')

and SharePointUriBuilder runs Uri.EscapeDataString on the value. An apostrophe therefore becomes %27 inside an OData string literal, which SharePoint does not accept — the literal has to be escaped by doubling the quote (''), not percent-encoded. An apostrophe is a perfectly legal SharePoint file name character, so this upload should succeed.

3. Colon — needs sanitization, encoding cannot help

On the Graph path, SharePointGraphUriBuilder.GetSpecificDriveUploadEndpoint correctly escapes the name (EscapePathSegments(FolderPath) + '/' + EscapeDataString(FileName)), so the colon reaches Graph as a literal colon in the item name. SharePoint/OneDrive forbid : * ? " < > / \ | in item names, so no encoding can make this work: the connector has to sanitize the name (or fail with a clear, actionable error) before calling the API.

Suggested fix
  • Escape apostrophes by doubling them for the OData literals used by the REST path.
  • Add a file-name sanitization step (reserved characters : * ? " < > / \ |, plus reserved names / leading-trailing spaces and dots) in Ext. SharePoint Connector Impl.CreateFile, ideally with an event so partners can override the replacement strategy, or at minimum a descriptive error instead of the raw API failure.
Expected behavior

The file is uploaded successfully whatever the file name is; characters that SharePoint cannot store are sanitized before the external API call (or the user gets an explicit error naming the offending characters, instead of a raw API failure).

Steps to reproduce
  1. Configure an External File Storage account of type SharePoint and enable external storage for document attachments.
  2. Attach a document whose file name contains a colon, e.g. Invoice: 2026-01.pdf, and upload it to external storage -> fails.
  3. Attach a document whose file name contains an apostrophe, e.g. Facture d'acompte.pdf, on an account with Use legacy REST API enabled -> fails.
  4. Drag & drop the same files directly into the SharePoint folder through the browser -> works (apostrophe case).
Additional context

No response

I will provide a fix for a bug
  • I will provide a fix for a bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in codeunit 4580 "Ext. SharePoint Connector Impl".CreateFile under src/Apps/W1/External File Storage - SharePoint Connector/App/src/, then trace the REST and Graph helper calls, including SharePointClientImpl.AddFileToFolder and the two URI builders. Reproduce both filename cases and add coverage for apostrophe escaping and reserved-character handling; done means valid names upload and invalid names receive sanitization or a descriptive error.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.