Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.writeFile API fails with non-ascii characters #912

Closed
lancetarn opened this issue Aug 1, 2020 · 1 comment
Closed

http.writeFile API fails with non-ascii characters #912

lancetarn opened this issue Aug 1, 2020 · 1 comment

Comments

@lancetarn
Copy link
Contributor

Describe the bug
Using writeFile API with unicode payload results in failed to match a command error.

To Reproduce
Implement a minimal function:

import {
  Dir, writeFile,
} from 'tauri/api/fs';

function pleaseWrite() {
  writeFile({ path: 'unicodeTest.txt', contents: 'å' }, { dir: Dir.Cache });
}

Receive the subsequent error in WebView console:

failed to match a command for {"callback":"499c79fd-8dde-4720-e708-d94956083059","error":"b4aa06f4-a06f-45b1-66d5-b69bdc463d43","cmd":"writeFile","path":"unicodeTest.txt","contents":"å","options":{"dir":2}}], trailing characters at line 1 column 178

Expected behavior
The file contents are written without error.

Platform and Versions (please complete the following information):

OS: macOS 10.14.6
Node: 12.18.0
NPM: 6.14.4
Yarn: -
Rustc: 1.45.0

taurijs: 0.11.0 (also appears in 0.10.0)
tauri.rs: 0.9.0 (also appears in 0.8.0)

Additional context
I realize that I have only been trying this in dev.

@kevinkassimo
Copy link

kevinkassimo commented Aug 1, 2020

Was about to file the exact same bug, but I think I have figured out the reason for this:

// transform `[payload]` to `payload`
let arg = arg.chars().skip(1).take(arg.len() - 2).collect::<String>();

Likely the use of .chars() breaks the behavior: per https://doc.rust-lang.org/std/string/struct.String.html#method.chars , the behavior might not be what we want here: .chars() iterates over Unicode Scalar Value instead (while arg.len() returns the byte length). Notice the example above

..."options":{"dir":2}}] // final ']' failed to be removed. This should have been removed

(I cannot try working on a fix myself due to some legal personal reasons atm, but hopefully this observation can help)

Update: I made a small mistake before, but it is still Unicode issue. Tested and seems replacing arg.len() with arg.chars().count() should work.

@jbolda jbolda closed this as completed in df70ca5 Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants