mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
reject double comma in id list
https://forums.ankiweb.net/t/anki-2-1-29-and-below-2-small-bugs/1496
This commit is contained in:
parent
6f76b86f7c
commit
01d20044e7
1 changed files with 8 additions and 4 deletions
|
@ -5,15 +5,16 @@ use crate::{
|
||||||
err::{AnkiError, Result},
|
err::{AnkiError, Result},
|
||||||
notetype::NoteTypeID,
|
notetype::NoteTypeID,
|
||||||
};
|
};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{escaped, is_not, tag, take_while1},
|
bytes::complete::{escaped, is_not, tag, take_while1},
|
||||||
character::complete::{anychar, char, one_of},
|
character::complete::{anychar, char, one_of},
|
||||||
character::is_digit,
|
|
||||||
combinator::{all_consuming, map, map_res},
|
combinator::{all_consuming, map, map_res},
|
||||||
sequence::{delimited, preceded, tuple},
|
sequence::{delimited, preceded, tuple},
|
||||||
{multi::many0, IResult},
|
{multi::many0, IResult},
|
||||||
};
|
};
|
||||||
|
use regex::Regex;
|
||||||
use std::{borrow::Cow, num};
|
use std::{borrow::Cow, num};
|
||||||
|
|
||||||
// fixme: need to preserve \ when used twice in string
|
// fixme: need to preserve \ when used twice in string
|
||||||
|
@ -294,10 +295,13 @@ fn search_node_for_text_with_argument<'a>(
|
||||||
/// ensure a list of ids contains only numbers and commas, returning unchanged if true
|
/// ensure a list of ids contains only numbers and commas, returning unchanged if true
|
||||||
/// used by nid: and cid:
|
/// used by nid: and cid:
|
||||||
fn check_id_list(s: Cow<str>) -> ParseResult<Cow<str>> {
|
fn check_id_list(s: Cow<str>) -> ParseResult<Cow<str>> {
|
||||||
if s.is_empty() || s.as_bytes().iter().any(|&c| !is_digit(c) && c != b',') {
|
lazy_static! {
|
||||||
Err(ParseError {})
|
static ref RE: Regex = Regex::new(r"^(\d+,)*\d+$").unwrap();
|
||||||
} else {
|
}
|
||||||
|
if RE.is_match(s.as_ref()) {
|
||||||
Ok(s)
|
Ok(s)
|
||||||
|
} else {
|
||||||
|
Err(ParseError {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue