[librsvg: 3/7] parse_str - do expect_exhausted here




commit 81944df88c881615d46c5e76c973bd820f560d73
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Sep 3 21:04:30 2020 -0500

    parse_str - do expect_exhausted here
    
    The parse() functions are supposed to be composable, so they should
    stop as soon as they consume a valid value.
    
    parse_str(), on the other hand, is meant to really parse the whole
    thing; it's a convenience function.  Therefore it should ensure that a
    single value was parsed, and nothing more.
    
    This also modifies NumberList analogously, which does not impl Parse,
    but has its own `parse` and `parse_str` functions for its custom
    NumberListLength parameter.

 rsvg_internals/src/number_list.rs | 6 +++---
 rsvg_internals/src/parsers.rs     | 5 ++++-
 2 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/rsvg_internals/src/number_list.rs b/rsvg_internals/src/number_list.rs
index 8675de47..3ae27ae2 100644
--- a/rsvg_internals/src/number_list.rs
+++ b/rsvg_internals/src/number_list.rs
@@ -54,8 +54,6 @@ impl NumberList {
             }
         }
 
-        parser.expect_exhausted()?;
-
         Ok(NumberList(v))
     }
 
@@ -63,7 +61,9 @@ impl NumberList {
         let mut input = ParserInput::new(s);
         let mut parser = Parser::new(&mut input);
 
-        Self::parse(&mut parser, length).map(|r| r)
+        let res = Self::parse(&mut parser, length)?;
+        parser.expect_exhausted()?;
+        Ok(res)
     }
 }
 
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index c9fb2e90..7d4577f8 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -21,7 +21,10 @@ pub trait Parse: Sized {
         let mut input = ParserInput::new(s);
         let mut parser = Parser::new(&mut input);
 
-        Self::parse(&mut parser).map(|r| r)
+        let res = Self::parse(&mut parser)?;
+        parser.expect_exhausted()?;
+
+        Ok(res)
     }
 }
 


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