mirror of
https://github.com/ankitects/anki.git
synced 2025-12-13 14:50:59 -05:00
Encode HTML entities in search errors
This commit is contained in:
parent
2a2ac38a1b
commit
182abfe66d
2 changed files with 51 additions and 12 deletions
|
|
@ -129,21 +129,45 @@ impl AnkiError {
|
||||||
SearchErrorKind::EmptyQuote => i18n.tr(TR::SearchEmptyQuote),
|
SearchErrorKind::EmptyQuote => i18n.tr(TR::SearchEmptyQuote),
|
||||||
SearchErrorKind::UnclosedQuote => i18n.tr(TR::SearchUnclosedQuote),
|
SearchErrorKind::UnclosedQuote => i18n.tr(TR::SearchUnclosedQuote),
|
||||||
SearchErrorKind::MissingKey => i18n.tr(TR::SearchMissingKey),
|
SearchErrorKind::MissingKey => i18n.tr(TR::SearchMissingKey),
|
||||||
SearchErrorKind::UnknownEscape(ctx) => i18n.trn(TR::SearchUnknownEscape, tr_strs!["val"=>(ctx)]).into(),
|
SearchErrorKind::UnknownEscape(ctx) => i18n
|
||||||
|
.trn(
|
||||||
|
TR::SearchUnknownEscape,
|
||||||
|
tr_strs!["val"=>(htmlescape::encode_minimal(ctx))],
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
SearchErrorKind::InvalidIdList => i18n.tr(TR::SearchInvalidIdList),
|
SearchErrorKind::InvalidIdList => i18n.tr(TR::SearchInvalidIdList),
|
||||||
SearchErrorKind::InvalidState => i18n.tr(TR::SearchInvalidState),
|
SearchErrorKind::InvalidState => i18n.tr(TR::SearchInvalidState),
|
||||||
SearchErrorKind::InvalidFlag => i18n.tr(TR::SearchInvalidFlag),
|
SearchErrorKind::InvalidFlag => i18n.tr(TR::SearchInvalidFlag),
|
||||||
SearchErrorKind::InvalidAdded => i18n.tr(TR::SearchInvalidAdded),
|
SearchErrorKind::InvalidAdded => i18n.tr(TR::SearchInvalidAdded),
|
||||||
SearchErrorKind::InvalidEdited => i18n.tr(TR::SearchInvalidEdited),
|
SearchErrorKind::InvalidEdited => i18n.tr(TR::SearchInvalidEdited),
|
||||||
SearchErrorKind::InvalidRatedDays => i18n.tr(TR::SearchInvalidRatedDays),
|
SearchErrorKind::InvalidRatedDays => i18n.tr(TR::SearchInvalidRatedDays),
|
||||||
SearchErrorKind::InvalidRatedEase(ctx) => i18n.trn(TR::SearchInvalidRatedEase, tr_strs!["val"=>(ctx)]).into(),
|
SearchErrorKind::InvalidRatedEase(ctx) => i18n
|
||||||
|
.trn(TR::SearchInvalidRatedEase, tr_strs!["val"=>(ctx)])
|
||||||
|
.into(),
|
||||||
SearchErrorKind::InvalidDupeMid => i18n.tr(TR::SearchInvalidDupeMid),
|
SearchErrorKind::InvalidDupeMid => i18n.tr(TR::SearchInvalidDupeMid),
|
||||||
SearchErrorKind::InvalidDupeText => i18n.tr(TR::SearchInvalidDupeText),
|
SearchErrorKind::InvalidDupeText => i18n.tr(TR::SearchInvalidDupeText),
|
||||||
SearchErrorKind::InvalidPropProperty => i18n.tr(TR::SearchInvalidPropProperty),
|
SearchErrorKind::InvalidPropProperty => i18n.tr(TR::SearchInvalidPropProperty),
|
||||||
SearchErrorKind::InvalidPropOperator(ctx) => i18n.trn(TR::SearchInvalidPropOperator, tr_strs!["val"=>(ctx)]).into(),
|
SearchErrorKind::InvalidPropOperator(ctx) => i18n
|
||||||
SearchErrorKind::InvalidPropFloat(ctx) => i18n.trn(TR::SearchInvalidPropFloat, tr_strs!["val"=>(ctx)]).into(),
|
.trn(TR::SearchInvalidPropOperator, tr_strs!["val"=>(ctx)])
|
||||||
SearchErrorKind::InvalidPropInteger(ctx) => i18n.trn(TR::SearchInvalidPropInteger, tr_strs!["val"=>(ctx)]).into(),
|
.into(),
|
||||||
SearchErrorKind::InvalidPropUnsigned(ctx) => i18n.trn(TR::SearchInvalidPropUnsigned, tr_strs!["val"=>(ctx)]).into(),
|
SearchErrorKind::InvalidPropFloat(ctx) => i18n
|
||||||
|
.trn(
|
||||||
|
TR::SearchInvalidPropFloat,
|
||||||
|
tr_strs!["val"=>(htmlescape::encode_minimal(ctx))],
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
SearchErrorKind::InvalidPropInteger(ctx) => i18n
|
||||||
|
.trn(
|
||||||
|
TR::SearchInvalidPropInteger,
|
||||||
|
tr_strs!["val"=>(htmlescape::encode_minimal(ctx))],
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
SearchErrorKind::InvalidPropUnsigned(ctx) => i18n
|
||||||
|
.trn(
|
||||||
|
TR::SearchInvalidPropUnsigned,
|
||||||
|
tr_strs!["val"=>(htmlescape::encode_minimal(ctx))],
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
SearchErrorKind::InvalidDid => i18n.tr(TR::SearchInvalidDid),
|
SearchErrorKind::InvalidDid => i18n.tr(TR::SearchInvalidDid),
|
||||||
SearchErrorKind::InvalidMid => i18n.tr(TR::SearchInvalidMid),
|
SearchErrorKind::InvalidMid => i18n.tr(TR::SearchInvalidMid),
|
||||||
SearchErrorKind::Regex(text) => text.into(),
|
SearchErrorKind::Regex(text) => text.into(),
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
decks::DeckID,
|
decks::DeckID,
|
||||||
err::{ParseError, SearchErrorKind as FailKind, Result},
|
err::{ParseError, Result, SearchErrorKind as FailKind},
|
||||||
notetype::NoteTypeID,
|
notetype::NoteTypeID,
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
@ -366,13 +366,19 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode<'static>> {
|
||||||
if let Ok(f) = num.parse::<f32>() {
|
if let Ok(f) = num.parse::<f32>() {
|
||||||
PropertyKind::Ease(f)
|
PropertyKind::Ease(f)
|
||||||
} else {
|
} else {
|
||||||
return Err(parse_failure(s, FailKind::InvalidPropFloat(format!("{}{}", prop, operator))));
|
return Err(parse_failure(
|
||||||
|
s,
|
||||||
|
FailKind::InvalidPropFloat(format!("{}{}", prop, operator)),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else if prop == "due" {
|
} else if prop == "due" {
|
||||||
if let Ok(i) = num.parse::<i32>() {
|
if let Ok(i) = num.parse::<i32>() {
|
||||||
PropertyKind::Due(i)
|
PropertyKind::Due(i)
|
||||||
} else {
|
} else {
|
||||||
return Err(parse_failure(s, FailKind::InvalidPropInteger(format!("{}{}", prop, operator))));
|
return Err(parse_failure(
|
||||||
|
s,
|
||||||
|
FailKind::InvalidPropInteger(format!("{}{}", prop, operator)),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else if let Ok(u) = num.parse::<u32>() {
|
} else if let Ok(u) = num.parse::<u32>() {
|
||||||
match prop {
|
match prop {
|
||||||
|
|
@ -383,7 +389,10 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode<'static>> {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(parse_failure(s, FailKind::InvalidPropUnsigned(format!("{}{}", prop, operator))));
|
return Err(parse_failure(
|
||||||
|
s,
|
||||||
|
FailKind::InvalidPropUnsigned(format!("{}{}", prop, operator)),
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(SearchNode::Property {
|
Ok(SearchNode::Property {
|
||||||
|
|
@ -421,10 +430,16 @@ fn parse_rated(s: &str) -> ParseResult<SearchNode> {
|
||||||
if u < 5 {
|
if u < 5 {
|
||||||
Some(u)
|
Some(u)
|
||||||
} else {
|
} else {
|
||||||
return Err(parse_failure(s, FailKind::InvalidRatedEase(days.to_string())));
|
return Err(parse_failure(
|
||||||
|
s,
|
||||||
|
FailKind::InvalidRatedEase(days.to_string()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(parse_failure(s, FailKind::InvalidRatedEase(days.to_string())));
|
return Err(parse_failure(
|
||||||
|
s,
|
||||||
|
FailKind::InvalidRatedEase(days.to_string()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue