From 593cad573baf239337c5869c92ea9e7aed61e847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cel=20=F0=9F=8C=B8?= Date: Sat, 2 Nov 2024 22:50:50 +0000 Subject: [PATCH] fix NCName and AttValue parsers --- src/xml/parsers.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/xml/parsers.rs b/src/xml/parsers.rs index 8bd07a8..3f67be7 100644 --- a/src/xml/parsers.rs +++ b/src/xml/parsers.rs @@ -1,6 +1,6 @@ use nom::{ branch::alt, - bytes::streaming::{is_a, tag, take, take_while}, + bytes::streaming::{is_a, is_not, tag, take, take_while}, character::{ complete::one_of, streaming::{char, none_of, satisfy}, @@ -61,16 +61,16 @@ impl Parser<'_, DefaultAttName> for DefaultAttName { } } +/// [5] Name ::= NameStartChar (NameChar)* /// [4] NCName ::= Name - (Char* ':' Char*) impl<'s> Parser<'s, NCName<'s>> for NCName<'s> { fn parse(input: &'s str) -> IResult<&str, NCName<'s>> { - map( - recognize(pair( - recognize(NameStartChar::parse).and_then(satisfy(|c| c != ':')), - many0(recognize(NameChar::parse).and_then(satisfy(|c| c != ':'))), - )), - |nc_name| NCName(nc_name), - )(input) + let (rest, name) = peek(recognize(Name::parse))(input)?; + if let Some(char) = name.find(':') { + map(take(char), |nc_name| NCName(nc_name))(input) + } else { + map(recognize(Name::parse), |nc_name| NCName(nc_name))(input) + } } } @@ -275,10 +275,7 @@ impl<'s> Parser<'s, AttValue<'s>> for AttValue<'s> { delimited( char('"'), many0(alt(( - map( - recognize(many_till(take(1usize), peek(one_of("%&\"")))), - |string| AttValueData::String(string), - ), + map(is_not("<&\""), |string| AttValueData::String(string)), map(Reference::parse, |reference| { AttValueData::Reference(reference) }), @@ -291,10 +288,7 @@ impl<'s> Parser<'s, AttValue<'s>> for AttValue<'s> { delimited( char('\''), many0(alt(( - map( - recognize(many_till(take(1usize), peek(one_of("%&'")))), - |string| AttValueData::String(string), - ), + map(is_not("<&'"), |string| AttValueData::String(string)), map(Reference::parse, |reference| { AttValueData::Reference(reference) }),