Skip to content

Commit

Permalink
PII censoring on test page.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Dec 10, 2023
1 parent 2a5de33 commit 8d2d6ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rustrict = { path = "..", features = ["trace_full", "width"] }
rustrict = { path = "..", features = ["trace_full", "width", "pii"] }
yew = { version = "0.21", features = ["csr"] }

[dependencies.web-sys]
Expand Down
5 changes: 3 additions & 2 deletions pages/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use web_sys::{HtmlInputElement, window, InputEvent, HtmlTextAreaElement, wasm_bindgen::JsCast};
use yew::{html, Html, Callback, function_component, TargetCast};
use rustrict::Censor;
use rustrict::{Censor, censor_and_analyze_pii};

#[function_component(App)]
fn app() -> Html {
let oninput = Callback::from(move |event: InputEvent| {
if let Some(input) = event.target_dyn_into::<HtmlInputElement>() {
let uncensored = input.value();
let (uncensored, pii) = censor_and_analyze_pii(&uncensored);
let analysis_element = window().unwrap().document().unwrap().get_element_by_id("analysis").unwrap();
let censored_element = window().unwrap().document().unwrap().get_element_by_id("censored").unwrap().dyn_into::<HtmlTextAreaElement>().unwrap();
if uncensored.is_empty() {
Expand All @@ -18,7 +19,7 @@ fn app() -> Html {
let count = censor.total_matches();
let detections = censor.detections();
let width = rustrict::width_str(&uncensored);
let result = format!("{analysis:?} (width = {width}, count = {count}, detections = {detections:?})");
let result = format!("{analysis:?} (width={width}, count={count}, detections={detections:?}, pii={pii:?})");
analysis_element.set_inner_html(&result);
censored_element.set_value(&censored);
}
Expand Down

0 comments on commit 8d2d6ff

Please sign in to comment.