-
Notifications
You must be signed in to change notification settings - Fork 94
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(chore): remove escape answer #2219
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
mm2src/mm2_main/src/rpc.rs
Outdated
let body_bytes = match std::str::from_utf8(&body) { | ||
Ok(body_utf8) => body_utf8.as_bytes().to_vec(), | ||
Err(_) => { | ||
return Response::builder() | ||
.status(500) | ||
.header(ACCESS_CONTROL_ALLOW_ORIGIN, rpc_cors) | ||
.header(CONTENT_TYPE, APPLICATION_JSON) | ||
.body(Body::from(err_to_rpc_json_string("Non UTF-8 output"))) | ||
.unwrap(); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to check if the bytes could be utf-8
ed at this point?
We should trust us.
use mm2_core::mm_ctx::MmArc; | ||
use mm2_err_handle::prelude::*; | ||
use mm2_rpc::mm_protocol::{MmRpcBuilder, MmRpcResponse, MmRpcVersion}; | ||
use regex::Regex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dropped the only usage of regex here,
we can also drop it in:
komodo-defi-framework/mm2src/mm2_main/Cargo.toml
Lines 80 to 82 in 079ea5e
# TODO: Reduce the size of regex by disabling the features we don't use. | |
# cf. https://github.com/rust-lang/regex/issues/583 | |
regex = "1" |
pub fn escape_answer<'a, S: Into<Cow<'a, str>>>(input: S) -> Cow<'a, str> { | ||
lazy_static! { | ||
static ref REGEX: Regex = Regex::new("[<>&]").unwrap(); | ||
} | ||
|
||
let input = input.into(); | ||
let mut last_match = 0; | ||
|
||
if REGEX.is_match(&input) { | ||
let matches = REGEX.find_iter(&input); | ||
let mut output = String::with_capacity(input.len()); | ||
for mat in matches { | ||
let (begin, end) = (mat.start(), mat.end()); | ||
output.push_str(&input[last_match..begin]); | ||
match &input[begin..end] { | ||
"<" => output.push_str("<"), | ||
">" => output.push_str(">"), | ||
"&" => output.push_str("&"), | ||
_ => unreachable!(), | ||
} | ||
last_match = end; | ||
} | ||
output.push_str(&input[last_match..]); | ||
Cow::Owned(output) | ||
} else { | ||
input | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea what was the motivation for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will wait for @onur-ozkan and @mariocynicys to complete their reviews before merging. Already discussed this with @smk762 in our internal chat so you can add this to the To Test
description @borngraced in the PR opening comment so that @smk762 remembers.
To Test
as discussed internally https://matrix.to/#/!yeLsKrHmWqEMEAILHs:matrix.org/$mAxamnv9Ga8rxAg24mXAUwRu9bKQArw2tB_aNaA177c?via=matrix.org, we need to test this doesn't break anything.