Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix: don't flag CVEs (#3582)

Andrew Dunbareec3e7e4df9a
diff --git a/harper-core/src/linting/numeric_range_en_dash.rs b/harper-core/src/linting/numeric_range_en_dash.rs
index 236ead8ff..547e1a1c1 100644
--- a/harper-core/src/linting/numeric_range_en_dash.rs
+++ b/harper-core/src/linting/numeric_range_en_dash.rs
@@ -1,7 +1,10 @@
-use crate::Token;
-use crate::expr::{Expr, SequenceExpr};
-use crate::linting::expr_linter::Chunk;
-use crate::punctuation::Punctuation;
+use crate::{
+ Token,
+ char_string::CharStringExt,
+ expr::{Expr, SequenceExpr},
+ linting::expr_linter::Chunk,
+ punctuation::Punctuation,
+};
use super::{ExprLinter, Lint, LintKind, Suggestion};
@@ -40,6 +43,14 @@ fn is_chained_numeric_form(context: Option<(&[Token], &[Token])>) -> bool {
preceded_by_numeric_dash || followed_by_dash_numeric
}
+fn is_cve(context: Option<(&[Token], &[Token])>, source: &[char]) -> bool {
+ context.is_some_and(|(before, _)| {
+ matches!(before, [.., word, hy]
+ if hy.kind.is_hyphen() && word.kind.is_word() && word.get_ch(source).eq_ch(&['c', 'v', 'e'])
+ )
+ })
+}
+
pub struct NumericRangeEnDash {
expr: SequenceExpr,
}
@@ -68,13 +79,17 @@ impl ExprLinter for NumericRangeEnDash {
fn match_to_lint_with_context(
&self,
matched_tokens: &[Token],
- _source: &[char],
+ source: &[char],
context: Option<(&[Token], &[Token])>,
) -> Option<Lint> {
if is_chained_numeric_form(context) {
return None;
}
+ if is_cve(context, source) {
+ return None;
+ }
+
Some(Lint {
span: matched_tokens[1].span,
lint_kind: LintKind::Formatting,
@@ -218,4 +233,9 @@ mod tests {
NumericRangeEnDash::default(),
);
}
+
+ #[test]
+ fn dont_flag_cve_3580() {
+ assert_no_lints("CVE-2017-5753", NumericRangeEnDash::default());
+ }
}