-
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(native-rpc): remove escaped response body #2219
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.
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.
LGTM!
Thanks
* dev: fix(orders): fix cancel order race condition using time-based cache (#2232) fix(legacy-swap): taker failed spend maker payment marked as failed (#2199) chore(adex-cli): deprecate adex-cli (#2234) feat(new-RPC): connection healthcheck implementation for peers (#2194) fix(proxy-signature): add message lifetime overflows (#2233) feat(CI): handle remote files in a safer way (#2217) chore(doc): update issue address in README (#2227) fix(merge): remove duplicated db_root function (#2229) feat(wallets): add `get_wallet_names` rpc (#2202) chore(tests): don't use `.wait()` and use `block_on` instead (#2220) fix(native-rpc): remove escaped response body (#2219) fix(clippy): fix coins mod clippy warnings in wasm (#2224) feat(core): handling CTRL-C signal with graceful shutdown (#2213) docs(README): fix typos (#2212) remove the non-sense arguments (#2216) fix(db): stop creating the all-zeroes dir on KDF start (#2218)
* dev: fix(orders): fix cancel order race condition using time-based cache (#2232) fix(legacy-swap): taker failed spend maker payment marked as failed (#2199) chore(adex-cli): deprecate adex-cli (#2234) feat(new-RPC): connection healthcheck implementation for peers (#2194) fix(proxy-signature): add message lifetime overflows (#2233) feat(CI): handle remote files in a safer way (#2217) chore(doc): update issue address in README (#2227) fix(merge): remove duplicated db_root function (#2229) feat(wallets): add `get_wallet_names` rpc (#2202) chore(tests): don't use `.wait()` and use `block_on` instead (#2220) fix(native-rpc): remove escaped response body (#2219) fix(clippy): fix coins mod clippy warnings in wasm (#2224) feat(core): handling CTRL-C signal with graceful shutdown (#2213) docs(README): fix typos (#2212) remove the non-sense arguments (#2216) fix(db): stop creating the all-zeroes dir on KDF start (#2218)
* dev: fix(cosmos): fix tx broadcasting error (#2238) chore(solana): remove solana implementation (#2239) chore(cli): remove leftover subcommands from help message (#2235) fix(orders): fix cancel order race condition using time-based cache (#2232) fix(legacy-swap): taker failed spend maker payment marked as failed (#2199) chore(adex-cli): deprecate adex-cli (#2234) feat(new-RPC): connection healthcheck implementation for peers (#2194) fix(proxy-signature): add message lifetime overflows (#2233) feat(CI): handle remote files in a safer way (#2217) chore(doc): update issue address in README (#2227) fix(merge): remove duplicated db_root function (#2229) feat(wallets): add `get_wallet_names` rpc (#2202) chore(tests): don't use `.wait()` and use `block_on` instead (#2220) fix(native-rpc): remove escaped response body (#2219) fix(clippy): fix coins mod clippy warnings in wasm (#2224) feat(core): handling CTRL-C signal with graceful shutdown (#2213) docs(README): fix typos (#2212) remove the non-sense arguments (#2216) fix(db): stop creating the all-zeroes dir on KDF start (#2218)
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.