[librsvg: 3/4] Detect empty strings as invalid in FilterValueList::parse




commit db15fd00bfef2728bda45f95b9ea1cfabe07d4ca
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Sep 9 10:43:37 2020 -0500

    Detect empty strings as invalid in FilterValueList::parse
    
    The spec allows "none | <filter-value-list>" and the latter cannot be empty.

 rsvg_internals/src/filter.rs | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index 1553763e..6af6a9d2 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -257,14 +257,19 @@ impl Parse for FilterValueList {
             return Ok(result);
         }
 
-        while !parser.is_exhausted() {
-            let loc = parser.current_source_location();
+        loop {
+            let state = parser.state();
 
-            if let Ok(IRI::Resource(uri)) = IRI::parse(parser) {
+            if let Ok(IRI::Resource(uri)) = parser.try_parse(|p| IRI::parse(p)) {
                 result.0.push(FilterValue::URL(uri));
             } else {
-                let token = parser.next()?;
-                return Err(loc.new_basic_unexpected_token_error(token.clone()).into());
+                parser.reset(&state);
+                let token = parser.next()?.clone();
+                return Err(parser.new_basic_unexpected_token_error(token).into());
+            }
+
+            if parser.is_exhausted() {
+                break;
             }
         }
 
@@ -296,6 +301,7 @@ mod tests {
 
     #[test]
     fn detects_invalid_filter_value_list() {
+        assert!(FilterValueList::parse_str("").is_err());
         assert!(FilterValueList::parse_str("fail").is_err());
         assert!(FilterValueList::parse_str("url(#test) none").is_err());
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]