on master help sign in
Fix less version parsing for minor versions of less

Less 581.2 is here, and it has a ".2" in the version string, which can't be parsed as a usize. Update the check to find a non-digit character rather than a space. This ignores the minor version, but parses the major version correctly.

commit91a347bf6d549ba543f1b4bfdc2a05f269c975c8 authorAllen Wild <allenwild93@gmail.com> dateSun 2 May 2021, 14:58 (6 years ago) parente219c8f
1 file changed+14−1
src/less.rs+14−1
src/less.rs+14−1
@@ -11,7 +11,7 @@ pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
1111fn parse_less_version(output: &[u8]) -> Option<usize> {
1212 if output.starts_with(b"less ") {
1313 let version = std::str::from_utf8(&output[5..]).ok()?;
14− let end = version.find(' ')?;
14+ let end = version.find(|c: char| !c.is_ascii_digit())?;
1515 version[..end].parse::<usize>().ok()
1616 } else {
1717 None
@@ -57,6 +57,19 @@ Home page: http://www.greenwoodsoftware.com/less";
5757 assert_eq!(Some(551), parse_less_version(output));
5858}
5959
60+#[test]
61+fn test_parse_less_version_581_2() {
62+ let output = b"less 581.2 (PCRE2 regular expressions)
63+Copyright (C) 1984-2021 Mark Nudelman
64+
65+less comes with NO WARRANTY, to the extent permitted by law.
66+For information about the terms of redistribution,
67+see the file named README in the less distribution.
68+Home page: https://greenwoodsoftware.com/less";
69+
70+ assert_eq!(Some(581), parse_less_version(output));
71+}
72+
6073#[test]
6174fn test_parse_less_version_wrong_program() {
6275 let output = b"more from util-linux 2.34";