coddingtonbear / obsidian-local-rest-api

Unlock your automation needs by interacting with your notes in Obsidian over a secure REST API.
MIT License
607 stars 56 forks source link

【BUG】 PATCH method to append content under a heading with Chinese #126

Closed fornewfork closed 1 month ago

fornewfork commented 1 month ago

Issue Description

When using the PATCH method to append content under a specific heading in a note, the operation fails if the note title contains non-ASCII characters (e.g., Chinese characters).

Steps to Reproduce

  1. Install the Local Rest API plugin in Obsidian.
  2. Attempt to use the PATCH method as described in the API documentation: https://coddingtonbear.github.io/obsidian-local-rest-api/#/Vault%20Files/patch_vault__filename_
  3. Try to append content to a note with a non-ASCII title (e.g., "待整理").

Expected Behavior

The PATCH operation should successfully append content to the specified heading, regardless of the note title's character set.

Actual Behavior

When the note title contains non-ASCII characters, the operation fails with the following error:

Could not send content to Obsidian: Error: TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Failed to read the 'headers' property from 'RequestInit': String contains non ISO-8859-1 code point.

Additional Information

coddingtonbear commented 1 month ago

Thanks for the report, @fornewfork! I have bad news and good news, unfortunately.

First: I'm sorry to tell you that that error message you've posted above is being given to you by the client side, not from the API itself. Unfortunately, that's an unavoidable reality because it's not technically possible to encode non-ASCII characters in an HTTP header; this means that, as you've discovered, using this particular feature for appending to headings that are written in non-ASCII characters is not a technical possibility with this API as it is designed today.

Good news, though: the PATCH API is being revised in the next major release of this library. So, I'm genuinely glad that you took the time to raise this specific problem to me because until you posted this issue, I hadn't considered what limitations this API's use of HTTP headers might impose! So, in the next version of this API, we'll be adding a feature that will allow the field into which you put your target heading to be encoded for transport (see Target-Encoding here: https://github.com/coddingtonbear/obsidian-local-rest-api/wiki/Flexible-PATCH#possible-future-api). Once that new feature is released, you should be able to accomplish what you want to do!

If you want to keep up with when that feature is released, follow https://github.com/coddingtonbear/obsidian-local-rest-api/issues/26 -- I'll be posting updates there!