mkaczanowski / pastebin

Simple, fast, standalone pastebin service
MIT License
155 stars 27 forks source link

use from_utf8_lossy to avoid server error on invalid text data #18

Closed fabioanderegg closed 3 years ago

fabioanderegg commented 3 years ago

When viewing a page that contains invalid UTF-8, I get the following error in the log file:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 3077, error_len: Some(1) }', src/main.rs:417:69

My fix replaces invalid data with the �, see documentation here: https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf8_lossy

mkaczanowski commented 3 years ago

nice catch. It would be great if u could add a unittest for that :)

fabioanderegg commented 3 years ago

I updated the pull request with a test case. Not too familiar with Rust yet, not sure if it's possible to create the string without unsafe.