Skip to content

Commit

Permalink
Merge pull request #4 from linw1995/fix/bearql_issue
Browse files Browse the repository at this point in the history
Fix BearQL parsing error
  • Loading branch information
linw1995 authored Aug 7, 2024
2 parents 2b9a75e + c0a1d7c commit 97f138e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/db/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type BookmarkFilter = Box<
fn join_folder_path(cwd: &str, p: &str) -> String {
const PATH_SEP: char = '/';
if p.starts_with(PATH_SEP) {
p.to_string()
p.trim_end_matches(PATH_SEP).to_string()
} else {
cwd.trim_end_matches(PATH_SEP)
.split(PATH_SEP)
Expand Down Expand Up @@ -319,6 +319,7 @@ pub(crate) mod test {
("./langs/rust//", Path("./langs/rust//".into())),
("//", Path("//".into())),
(".//", Path(".//".into())),
("/blog/", Path("/blog/".into())),
(
"rust | langs go",
Or(
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod db;
pub mod utils;

#[cfg(test)]
#[cfg(not(tarpaulin_include))]
#[ctor::ctor]
fn init() {
crate::utils::logging::setup_console_log();
Expand Down
8 changes: 8 additions & 0 deletions src/utils/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub enum Path<'a> {
pub enum RelativePath<'a> {
#[parse("{0}/{1}")]
Join(Keyword<'a>, &'a Self),
#[parse("{0}/")]
NameEndSlash(Keyword<'a>),
#[parse("{0}")]
Name(Keyword<'a>),
#[parse("/")] // for tailing "/", "//" ... syntax
Expand Down Expand Up @@ -145,6 +147,11 @@ fn _path_to_str_parts<'a>(p: Path<'a>, parts: &mut Vec<&'a str>) {
parts.push(item.into());
false
}
RelativePath::NameEndSlash(item) => {
parts.push(item.into());
parts.push("");
false
}
RelativePath::ExtraSlash() => {
parts.push("");
parts.push("");
Expand Down Expand Up @@ -187,6 +194,7 @@ mod test {
r#"title | #rust #langs"#,
r#"title ( #rust #langs )"#,
r#"title ( #rust | #langs )"#,
r#"/blog/"#,
] {
let rv = parse_query(&src, &out_arena, &err_arena);
info!(?rv, ?src, "parsed");
Expand Down

0 comments on commit 97f138e

Please sign in to comment.