From 4f2214e1d61606c7ca9a270de42c61b86e3c50be Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 17 Apr 2024 22:55:08 +0200 Subject: [PATCH] terminal: Treat paths with non-digit col/rows as paths nonetheless (#10691) This relaxes path parsing to allow paths like ./foo.rs:food or ./food/foo_bar.rs:2:12:food as some tools may add a suffix without regard for col/row end. Fixes #10688 Release Notes: - Made path parsing in terminal (for directory links) more lenient with regards to row/column fields. --- crates/util/src/paths.rs | 44 ++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rs index 6bbc1f212e98eb96ee20ef2c5622fd00bf899918..97740fb75c8634675c0a4a780c957e48d09fbc2d 100644 --- a/crates/util/src/paths.rs +++ b/crates/util/src/paths.rs @@ -205,23 +205,27 @@ impl

PathLikeWithPosition

{ column: None, }) } else { - let maybe_col_str = - if maybe_col_str.ends_with(FILE_ROW_COLUMN_DELIMITER) { - &maybe_col_str[..maybe_col_str.len() - 1] - } else { - maybe_col_str - }; + let (maybe_col_str, _) = + maybe_col_str.split_once(':').unwrap_or((maybe_col_str, "")); match maybe_col_str.parse::() { Ok(col) => Ok(Self { path_like: parse_path_like_str(path_like_str)?, row: Some(row), column: Some(col), }), - Err(_) => fallback(s), + Err(_) => Ok(Self { + path_like: parse_path_like_str(path_like_str)?, + row: Some(row), + column: None, + }), } } } - Err(_) => fallback(s), + Err(_) => Ok(Self { + path_like: parse_path_like_str(path_like_str)?, + row: None, + column: None, + }), } } } @@ -352,23 +356,23 @@ mod tests { #[test] fn path_with_position_parsing_negative() { - for input in [ - "test_file.rs:a", - "test_file.rs:a:b", - "test_file.rs::", - "test_file.rs::1", - "test_file.rs:1::", - "test_file.rs::1:2", - "test_file.rs:1::2", - "test_file.rs:1:2:3", + for (input, row, column) in [ + ("test_file.rs:a", None, None), + ("test_file.rs:a:b", None, None), + ("test_file.rs::", None, None), + ("test_file.rs::1", None, None), + ("test_file.rs:1::", Some(1), None), + ("test_file.rs::1:2", None, None), + ("test_file.rs:1::2", Some(1), None), + ("test_file.rs:1:2:3", Some(1), Some(2)), ] { let actual = parse_str(input); assert_eq!( actual, PathLikeWithPosition { - path_like: input.to_string(), - row: None, - column: None, + path_like: "test_file.rs".to_string(), + row, + column, }, "For negative case input str '{input}', got a parse mismatch" );