Skip to content
Open
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
19 changes: 0 additions & 19 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,3 @@ jobs:

- name: Run rustfmt
run: find crates -name "*.rs" -exec rustfmt --check {} \;

security:
name: Audit
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ github.sha }}

- name: Set up Rust cache
uses: Swatinem/rust-cache@v2

- name: Install cargo-audit
run: cargo install cargo-audit

- name: Audit dependencies
run: cargo audit

48 changes: 48 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2025-2026 Zensical and contributors

# SPDX-License-Identifier: MIT
# Third-party contributions licensed under DCO

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

name: Security

on:
schedule:
- cron: "0 4 * * 1"
workflow_dispatch:

jobs:
audit:
name: Audit
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ github.sha }}

- name: Set up Rust cache
uses: Swatinem/rust-cache@v2

- name: Install cargo-audit
run: cargo install cargo-audit

- name: Audit dependencies
run: cargo audit
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ zrx-store = { version = "0.0.10", path = "crates/zrx-store" }
zrx-stream = { version = "0.0.22", path = "crates/zrx-stream" }

ahash = "0.8.12"
anyhow = "1.0.102"
anyhow = "1.0.103"
crossbeam = "0.8.4"
file-id = "0.2.3"
globset = "0.4.18"
Expand Down
17 changes: 17 additions & 0 deletions crates/zrx-id/src/id/expression/filter/candidates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,22 @@ mod tests {
}
Ok(())
}

#[test]
fn handles_default() -> Result {
let mut builder = Filter::builder();
let _ = builder.insert(Expression::default());
let filter = builder.build()?;
for (id, check) in [
("zri:file:::docs:index.md:", vec![0]),
("zri:git:::docs:image.jpg:", vec![0]),
] {
assert_eq!(
filter.candidates(&id)?.collect::<Vec<_>>(), // fmt
check
);
}
Ok(())
}
}
}
27 changes: 16 additions & 11 deletions crates/zrx-id/src/id/specificity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ impl Specificity {
/// Computes the sum of both specificities.
#[inline]
fn sum(self, other: Self) -> Self {
let Specificity(a1, b1, c1, l1) = self;
let Specificity(a2, b2, c2, l2) = other;
let Self(a1, b1, c1, l1) = self;
let Self(a2, b2, c2, l2) = other;
Self(
a1.saturating_add(a2),
b1.saturating_add(b2),
Expand All @@ -158,6 +158,13 @@ impl Specificity {
spec.3 = self.3.saturating_add(other.3);
spec
}

/// Returns whether the specificity is zero.
#[inline]
fn is_zero(self) -> bool {
let Self(a, b, c, l) = self;
a | b | c | l == 0
}
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -229,16 +236,14 @@ impl Ord for Specificity {
/// ```
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
let Specificity(a1, b1, c1, l1) = self;
let Specificity(a2, b2, c2, l2) = other;
let Self(a1, b1, c1, l1) = self;
let Self(a2, b2, c2, l2) = other;

// An all-zero specificity is the least specific and must always be the
// first in order, so check if this applies to any of the specificities
if a1 | b1 | c1 | l1 == 0 {
return Ordering::Less;
}
if a2 | b2 | c2 | l2 == 0 {
return Ordering::Greater;
// An all-zero specificity is always less specific than a non-zero
// specificity, but two all-zero specificities must compare equal
let ordering = other.is_zero().cmp(&self.is_zero());
if !ordering.is_eq() {
return ordering;
}

// Otherwise, compare each component, where `c` is reversed since fewer
Expand Down
Loading