refactor: improve dot separator parsing in command parser

Change split_on_dot() to require dot to be a standalone word
surrounded by whitespace or at line boundaries, rather than any
dot character.

This prevents accidental splitting on dots within identifiers or
quoted strings, making the command syntax more predictable.

The new logic checks both preceding and following bytes to ensure
the dot is truly isolated before treating it as a separator.

Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M)
This commit is contained in:
Edward Langley
2026-04-05 01:07:08 -07:00
parent 82ad459c4e
commit d3a1a57c78

View File

@ -37,18 +37,24 @@ pub fn parse_line_with(registry: &CmdRegistry, line: &str) -> Result<Vec<Box<dyn
Ok(commands)
}
/// Split a line on `.` separators, respecting quoted strings.
/// Split a line on ` . ` separators (dot must be a standalone word,
/// surrounded by whitespace or at line boundaries). Respects quoted strings.
fn split_on_dot(line: &str) -> Vec<&str> {
let mut segments = Vec::new();
let mut start = 0;
let mut in_quote = false;
let bytes = line.as_bytes();
for (i, c) in line.char_indices() {
match c {
'"' => in_quote = !in_quote,
'.' if !in_quote => {
segments.push(&line[start..i]);
start = i + 1;
let before_ws = i == 0 || bytes[i - 1].is_ascii_whitespace();
let after_ws = i + 1 >= bytes.len() || bytes[i + 1].is_ascii_whitespace();
if before_ws && after_ws {
segments.push(&line[start..i]);
start = i + 1;
}
}
_ => {}
}