From 46c3c075d186f281272fa871be278a12091c57de Mon Sep 17 00:00:00 2001 From: John Turner Date: Tue, 18 Nov 2025 02:20:57 +0000 Subject: [PATCH] disallow atoms that end in what could be a valid version --- src/atom/parsers.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/atom/parsers.rs b/src/atom/parsers.rs index 59bd23f..109e3bc 100644 --- a/src/atom/parsers.rs +++ b/src/atom/parsers.rs @@ -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 {