Xero-NetStandard icon indicating copy to clipboard operation
Xero-NetStandard copied to clipboard

Attach Invoice With Spaces in Filename Causes 404 Error - Xero.NetStandard.OAuth2 9.2.0

Open phil000 opened this issue 1 year ago • 8 comments

SDK you're using (please complete the following information):

  • Version Xero.NetStandard.OAuth2 9.2.0

Describe the bug We have upgraded from Xero.NetStandard.OAuth2 6.0.0 to Xero.NetStandard.OAuth2 9.2.0 When uploading files to attach to an invoice we now get an error code 404, with error content "The resource you're looking for cannot be found" If we remove the spaces from the filename the upload works correctly. We have noticed that this error was introduced in Xero.NetStandard.OAuth2 9.0.0 The issue does not occur in 8.1.0.

To Reproduce Upload a file with spaces.

image

Expected behavior File attachment with spaces can be uploaded via .NET API.

phil000 avatar Oct 14 '24 20:10 phil000

PETOSS-645

github-actions[bot] avatar Oct 14 '24 20:10 github-actions[bot]

Thanks for raising an issue, a ticket has been created to track your request

github-actions[bot] avatar Oct 14 '24 20:10 github-actions[bot]

We have noted that while the documentation states: "When the file name includes special characters, the characters should not be encoded unless they're brackets. Brackets must be encoded in order for the call to go through, and all other characters must be unencoded"

If we actually URL path encode the filename the filename with spaces can be uploaded again. (This means replacing spaces with %20, not +)

phil000 avatar Oct 28 '24 01:10 phil000

This just happened to me, I had to use System.Uri.EscapeDataString instead of WebUtility.UrlEncode

DanPatten avatar Nov 01 '24 06:11 DanPatten

Yes, FYI the answer is to use System.Uri.EscapeDataString that escapes spaces as "%20"

System.Net.WebUtility.UrlEncode encodes spaces as '+' which does not work.

phil000 avatar Nov 01 '24 06:11 phil000

Can the change be listed in releases as a breaking change? This broke production when our users started getting errors after upgrading and there is no mention of this in the changelog.

DanPatten avatar Nov 01 '24 13:11 DanPatten

Yes, FYI the answer is to use System.Uri.EscapeDataString that escapes spaces as "%20"

System.Net.WebUtility.UrlEncode encodes spaces as '+' which does not work.

+1, this is what RestSharp is using (and therefore what this SDK was using up to 9.x.x).

For reference:

This raises the question of whether compatibility with massive URLs should also be preserved as part of the fix? Seems like the sensible option given we can simply adopt RestSharp's method - there's a simplified version in the codebase already.

joshsj avatar Nov 01 '24 15:11 joshsj

Anything happening here? This seems like a pretty major and unnecessary breaking change. Please un-break ASAP.

phil000 avatar Feb 05 '25 03:02 phil000