fix(native-rpc): remove escaped response body#2219
Conversation
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.
Do we really need to check if the bytes could be utf-8ed 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.
we dropped the only usage of regex here,
we can also drop it in: https://github.com/KomodoPlatform/komodo-defi-framework/blob/079ea5e4fd9929a73a6f3a7f62240933d7537a43/mm2src/mm2_main/Cargo.toml#L80-L82
| 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.
Any idea what was the motivation for this?
There was a problem hiding this comment.
shamardy
left a comment
There was a problem hiding this comment.
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.
* 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.