Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case-consistency searching sqlite history #777

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/history/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ mod test {
Ok(())
}

#[test]
fn search_prefix_is_case_sensitive() -> Result<()> {
// Basic prefix search should preserve case
//
// https://github.com/nushell/nushell/issues/10131
let history = create_filled_example_history()?;
let res = history.search(SearchQuery {
filter: SearchFilter::from_text_search(
CommandLineSearch::Prefix("LS ".to_string()),
None,
),
..SearchQuery::everything(SearchDirection::Backward, None)
})?;
search_returned(&*history, res, vec![])?;

Ok(())
}

#[test]
fn search_includes() -> Result<()> {
let history = create_filled_example_history()?;
Expand Down
20 changes: 13 additions & 7 deletions src/history/sqlite_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,20 @@ impl SqliteBackedHistory {
None => "",
};
if let Some(command_line) = &query.filter.command_line {
// TODO: escape %
let command_line_like = match command_line {
CommandLineSearch::Exact(e) => e.to_string(),
CommandLineSearch::Prefix(prefix) => format!("{prefix}%"),
CommandLineSearch::Substring(cont) => format!("%{cont}%"),
match command_line {
CommandLineSearch::Exact(e) => {
wheres.push("command_line == :command_line");
params.push((":command_line", Box::new(e)));
}
CommandLineSearch::Prefix(prefix) => {
wheres.push("instr(command_line, :command_line) == 1");
params.push((":command_line", Box::new(prefix)));
}
CommandLineSearch::Substring(cont) => {
wheres.push("instr(command_line, :command_line) >= 1");
params.push((":command_line", Box::new(cont)));
}
};
wheres.push("command_line like :command_line");
params.push((":command_line", Box::new(command_line_like)));
}

if let Some(str) = &query.filter.not_command_line {
Expand Down
Loading