OneDrive Sync Issues Due to HTML chars in Code Blocks

Operating system

Windows

Joplin version

2.14.20

Desktop version info

Joplin 2.14.20 (prod, win32)

Client ID: 01378fa8087c49f69c3d9731cef891a2
Sync Version: 3
Profile Version: 46
Keychain Supported: Yes

Revision: cfd98e3

Backup: 1.4.0

Sync target

OneDrive

What issue do you have?

I've been running into the following error since Friday 26 APR 2024: Last error: Error: On file be29de88abcd48fca162445a8d7c4762.md: Could not execute request after multiple attempts: GET hxxps : / / graph[.]microsoft[.]com/v1.0/drive/root:/Apps/Joplin/be29de88abcd48fca162445a8d7c4762.md:/content

I've encountered this error on both mac and windows, both of which are using the latest Joplin client. This morning I backed up everything from Joplin via a jex backup and began troubleshooting.

The two notes I kept having issues with included the following code (in single line or multi line code blocks)

<? php $_GET['location'] ?>

If I don't include the < or > characters the note uploads fine. If I escape those characters in the code block, the note uploads fine.

I think the parsing function needs to be checked when uploading the files to OneDrive (not sure if this happens on other cloud providers) to add in escapes for those characters during upload, and then removing the escapes once we retrieve the content, so that the code can be directly copied between notes and apps.

What error did OneDrive report? This is most likely them who are blocking the upload

Just kicked off a sync with a test file that had the code in it:

2024-04-29 16:14:28: OneDriveApi: "SyntaxError: OneDriveApi::exec: Cannot parse JSON error: Unexpected end of JSON input
SyntaxError: OneDriveApi::exec: Cannot parse JSON error: Unexpected end of JSON input
at JSON.parse ()
at OneDriveApi. (C:\Program Files\Joplin\resources\app.asar\node_modules@joplin\lib\onedrive-api.js:325:46)
at Generator.next ()
at fulfilled (C:\Program Files\Joplin\resources\app.asar\node_modules@joplin\lib\onedrive-api.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
2024-04-29 16:14:34: OneDriveApi: "Got error below - retrying (1)..."
2024-04-29 16:14:34: OneDriveApi: "SyntaxError: OneDriveApi::exec: Cannot parse JSON error: Unexpected end of JSON input
SyntaxError: OneDriveApi::exec: Cannot parse JSON error: Unexpected end of JSON input
at JSON.parse ()
at OneDriveApi. (C:\Program Files\Joplin\resources\app.asar\node_modules@joplin\lib\onedrive-api.js:325:46)
at Generator.next ()
at fulfilled (C:\Program Files\Joplin\resources\app.asar\node_modules@joplin\lib\onedrive-api.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"

And the final error is the "Could not execute request after multiple attempts" error.

Did a few more variations of the code, and it always fails on the greater than or less than characters if they are not explicitly escaped via a backslash. Url encoded seems to fail occasionally as well, so it's likely getting rendered on their side.

Did you have a chance to give it a try to replicate the issue?

A new note with the following content syncs for me:

This is a test note with some PHP:

```php
<? php $_GET['location'] ?>
```

I think another user solved this by enabling end-to-end encryption. If you take this approach, be sure to make a backup of all data first. (Also be aware that end-to-end encryption will make sync slower).

i didn't list mine as php since it was mixed code, so i used a raw code block with no formatting. Let me go check and see if specifying it as a php code block fixes the issue.

Also, I thought the onedrive sync method for joplin stated not to use encryption?