From 8bf6c55d18344f9028d8810a16d3e0a72a4ecec1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 13 Mar 2021 10:16:10 +1000 Subject: [PATCH] Merge pull request #1067 from RumovZ/regex-err Fix regex error formatting and search error escaping --- rslib/src/err.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rslib/src/err.rs b/rslib/src/err.rs index 77f714599..39228ffc7 100644 --- a/rslib/src/err.rs +++ b/rslib/src/err.rs @@ -139,56 +139,56 @@ impl AnkiError { SearchErrorKind::UnknownEscape(ctx) => i18n .trn( TR::SearchUnknownEscape, - tr_strs!["val"=>(htmlescape::encode_minimal(ctx))], + tr_strs!["val"=>(ctx.replace('`', "'"))], ) .into(), SearchErrorKind::InvalidState(state) => i18n .trn( TR::SearchInvalidArgument, - tr_strs!("term" => "is:", "argument" => state), + tr_strs!("term" => "is:", "argument" => state.replace('`', "'")), ) .into(), SearchErrorKind::InvalidFlag => i18n.tr(TR::SearchInvalidFlag), SearchErrorKind::InvalidPropProperty(prop) => i18n .trn( TR::SearchInvalidArgument, - tr_strs!("term" => "prop:", "argument" => prop), + tr_strs!("term" => "prop:", "argument" => prop.replace('`', "'")), ) .into(), SearchErrorKind::InvalidPropOperator(ctx) => i18n .trn(TR::SearchInvalidPropOperator, tr_strs!["val"=>(ctx)]) .into(), - SearchErrorKind::Regex(text) => text.into(), + SearchErrorKind::Regex(text) => format!("
`{}`
", text.replace('`', "'")).into(), SearchErrorKind::Other(Some(info)) => info.into(), SearchErrorKind::Other(None) => i18n.tr(TR::SearchInvalidOther), SearchErrorKind::InvalidNumber { provided, context } => i18n .trn( TR::SearchInvalidNumber, - tr_strs!["provided"=>provided, "context"=>context], + tr_strs!["provided"=>provided.replace('`', "'"), "context"=>context.replace('`', "'")], ) .into(), SearchErrorKind::InvalidWholeNumber { provided, context } => i18n .trn( TR::SearchInvalidWholeNumber, - tr_strs!["provided"=>provided, "context"=>context], + tr_strs!["provided"=>provided.replace('`', "'"), "context"=>context.replace('`', "'")], ) .into(), SearchErrorKind::InvalidPositiveWholeNumber { provided, context } => i18n .trn( TR::SearchInvalidPositiveWholeNumber, - tr_strs!["provided"=>provided, "context"=>context], + tr_strs!["provided"=>provided.replace('`', "'"), "context"=>context.replace('`', "'")], ) .into(), SearchErrorKind::InvalidNegativeWholeNumber { provided, context } => i18n .trn( TR::SearchInvalidNegativeWholeNumber, - tr_strs!["provided"=>provided, "context"=>context], + tr_strs!["provided"=>provided.replace('`', "'"), "context"=>context.replace('`', "'")], ) .into(), SearchErrorKind::InvalidAnswerButton { provided, context } => i18n .trn( TR::SearchInvalidAnswerButton, - tr_strs!["provided"=>provided, "context"=>context], + tr_strs!["provided"=>provided.replace('`', "'"), "context"=>context.replace('`', "'")], ) .into(), };