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

Fix crashes with invalid utf-8. #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ emacs-macros = { path = "emacs-macros", version = "0.17.0" }
rustc_version = "0.2.3"

[features]
default = []
default = [ "utf-8-validation" ]
utf-8-validation = []
lossy-integer-conversion = []
nonzero-integer-conversion = []
Expand Down
4 changes: 2 additions & 2 deletions guide/src/type-conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ features = ["nonzero-integer-conversion"]

## Strings

By default, no utf-8 validation is done when converting Lisp strings into Rust strings, because the string data returned by Emacs is guaranteed to be valid utf-8 sequence. If you think you've otherwise encountered an Emacs bug, utf-8 validation can be enabled through a feature:
By default, utf-8 validation is enabled when converting Lisp strings into Rust strings, because the string data returned by Emacs is not guaranteed to be valid utf-8 sequence. If you require additional performance and don't care about possible undefined behavior and crashes, utf-8 validation can be disabled through a feature `utf-8-validation`:

```toml
[dependencies.emacs]
features = ["utf-8-validation"]
default-features = false
```

## Vectors
Expand Down
2 changes: 1 addition & 1 deletion src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl FromLisp<'_> for String {
#[cfg(feature = "utf-8-validation")]
fn from_lisp(value: Value<'_>) -> Result<Self> {
let bytes = value.env.string_bytes(value)?;
Ok(String::from_utf8(bytes).unwrap())
String::from_utf8(bytes).map_err(|e| e.into())
}
}

Expand Down