Skip to content

Commit

Permalink
fix panic on message escape
Browse files Browse the repository at this point in the history
  • Loading branch information
n-hass committed Jun 6, 2024
1 parent e7c8a7f commit ce85965
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix",
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
"terminal.integrated.defaultProfile.linux": "zsh with nix-shell",
}
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "telelog"
version = "0.2.1"
version = "0.2.2"
edition = "2021"

[dependencies]
Expand Down
10 changes: 8 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub fn colour_translate(priority: u8) -> String {

pub fn escape_message(message: &str) -> String {
let mut message = message.to_string();

if message.starts_with("<code>") {
message = message.strip_prefix("<code>").unwrap_or("").to_string();
}
Expand All @@ -86,10 +87,15 @@ pub fn escape_message(message: &str) -> String {
message = message.strip_suffix("</code>").unwrap_or("").to_string();
}

message
message = message
.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&#39;")
.replace("'", "&#39;");


message = "<code>".to_string() + &message + "</code>";

message
}

0 comments on commit ce85965

Please sign in to comment.