Skip to content

Commit

Permalink
Merge pull request #235 from kevinaboos/html_encode_linkified_text_body
Browse files Browse the repository at this point in the history
Html encode linkified text body
  • Loading branch information
kevinaboos authored Nov 4, 2024
2 parents 5bac958 + 185aee8 commit 3784a78
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ crossbeam-queue = "0.3.8"
eyeball = { version = "0.8.8", features = ["tracing"] }
eyeball-im = "0.5.0"
futures-util = "0.3"
htmlize = "1.0.5"
imbl = { version = "3.0.0", features = ["serde"] } # same as matrix-sdk-ui
imghdr = "0.7.0"
linkify = "0.10.0"
Expand Down
17 changes: 12 additions & 5 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,9 +885,16 @@ async fn async_main_loop(
let most_recent_user_id = persistent_state::most_recent_user_id();
log!("Most recent user ID: {most_recent_user_id:?}");
let cli_parse_result = Cli::try_parse();
log!("CLI parsing succeeded? {}", cli_parse_result.is_ok());
let wait_for_login = most_recent_user_id.is_none()
|| std::env::args().any(|arg| arg == "--login-screen" || arg == "--force-login");
let cli_has_valid_username_password = cli_parse_result.as_ref()
.is_ok_and(|cli| !cli.username.is_empty() && !cli.password.is_empty());
log!("CLI parsing succeeded? {}. CLI has valid UN+PW? {}",
cli_parse_result.as_ref().is_ok(),
cli_has_valid_username_password,
);
let wait_for_login = !cli_has_valid_username_password && (
most_recent_user_id.is_none()
|| std::env::args().any(|arg| arg == "--login-screen" || arg == "--force-login")
);
log!("Waiting for login? {}", wait_for_login);

let new_login_opt = if !wait_for_login {
Expand All @@ -903,12 +910,12 @@ async fn async_main_loop(
if let Some(session) = persistent_state::restore_session(specified_username).await.ok() {
Some(session)
} else {
let status_err = "Error: failed to restore previous user session. Please login again.";
let status_err = "Failed to restore previous user session. Please login again.";
log!("{status_err}");
Cx::post_action(LoginAction::Status(status_err.to_string()));

if let Ok(cli) = cli_parse_result {
let status_str = format!("Attempting auto-login from CLI arguments as user {}...", cli.username);
let status_str = format!("Attempting auto-login from CLI arguments as user '{}'...", cli.username);
log!("{status_str}");
Cx::post_action(LoginAction::Status(status_str));

Expand Down
8 changes: 5 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,21 @@ pub fn linkify<'s>(text: &'s str) -> Cow<'s, str> {
match link.kind() {
&LinkKind::Url => {
linkified_text = format!(
"{linkified_text}{}<a href=\"{link_txt}\">{link_txt}</a>",
"{linkified_text}{}<a href=\"{link_txt}\">{}</a>",
text.get(last_end_index..link.start()).unwrap_or_default(),
htmlize::escape_attribute(link_txt),
);
}
&LinkKind::Email => {
linkified_text = format!(
"{linkified_text}{}<a href=\"mailto:{link_txt}\">{link_txt}</a>",
"{linkified_text}{}<a href=\"mailto:{link_txt}\">{}</a>",
text.get(last_end_index..link.start()).unwrap_or_default(),
htmlize::escape_attribute(link_txt),
);
}
_ => return Cow::Borrowed(text), // unreachable
}
}
}
last_end_index = link.end();
}
linkified_text.push_str(text.get(last_end_index..).unwrap_or_default());
Expand Down

0 comments on commit 3784a78

Please sign in to comment.