forked from gentoo-utils/gentoo-utils
disallow atoms that end in what could be a valid version
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use core::option::Option::None;
|
||||
|
||||
use mon::{Parser, ParserIter, alphanumeric, r#if, numeric1, one_of, tag};
|
||||
use mon::{Parser, ParserIter, alphanumeric, eof, r#if, input::InputIter, numeric1, one_of, tag};
|
||||
|
||||
use crate::{
|
||||
Parseable,
|
||||
@@ -126,7 +126,7 @@ impl<'a> Parseable<'a, &'a str> for Name {
|
||||
type Parser = impl Parser<&'a str, Output = Self>;
|
||||
|
||||
fn parser() -> Self::Parser {
|
||||
let start = alphanumeric().or(one_of("_".chars()));
|
||||
let start = || alphanumeric().or(one_of("_".chars()));
|
||||
|
||||
let rest = alphanumeric()
|
||||
.or(one_of("_+".chars()))
|
||||
@@ -138,9 +138,19 @@ impl<'a> Parseable<'a, &'a str> for Name {
|
||||
.repeated()
|
||||
.many();
|
||||
|
||||
start
|
||||
let verify = alphanumeric()
|
||||
.or(one_of("_+".chars()))
|
||||
.or(one_of("-".chars())
|
||||
.and_not(Version::parser().preceded_by(tag("-")).followed_by(eof())))
|
||||
.repeated()
|
||||
.many();
|
||||
|
||||
start()
|
||||
.and(rest)
|
||||
.recognize()
|
||||
.verify_output(move |output: &&str| {
|
||||
verify.check_finished(InputIter::new(*output)).is_ok()
|
||||
})
|
||||
.map(|output: &str| Name(output.to_string()))
|
||||
}
|
||||
}
|
||||
@@ -541,6 +551,7 @@ mod test {
|
||||
"media-libs/libsdl2[haptitick(+),sound(+)vd,eio(+)]",
|
||||
"=kde-frameworks/kcodecs-6.19*86",
|
||||
"=dev-ml/stdio-0.17*t:=[ocamlopt?]",
|
||||
">=dev-libs/libgee-0-8.5:0..8=",
|
||||
];
|
||||
|
||||
for atom in atoms {
|
||||
|
||||
Reference in New Issue
Block a user