Skip to content

Commit 65cc01d

Browse files
committed
Rename highlight limits to better describe them
1 parent 8b2b343 commit 65cc01d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/web/highlight.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use syntect::{
66
util::LinesWithEndings,
77
};
88

9-
const CODE_SIZE_LIMIT: usize = 2 * 1024 * 1024;
10-
const LINE_SIZE_LIMIT: usize = 512;
9+
const TOTAL_CODE_BYTE_LENGTH_LIMIT: usize = 2 * 1024 * 1024;
10+
const PER_LINE_BYTE_LENGTH_LIMIT: usize = 512;
1111

1212
#[derive(Debug, thiserror::Error)]
1313
#[error("the code exceeded a highlighting limit")]
@@ -29,7 +29,7 @@ static SYNTAXES: Lazy<SyntaxSet> = Lazy::new(|| {
2929
});
3030

3131
fn try_with_syntax(syntax: &SyntaxReference, code: &str) -> Result<String> {
32-
if code.len() > CODE_SIZE_LIMIT {
32+
if code.len() > TOTAL_CODE_BYTE_LENGTH_LIMIT {
3333
return Err(LimitsExceeded.into());
3434
}
3535

@@ -40,7 +40,7 @@ fn try_with_syntax(syntax: &SyntaxReference, code: &str) -> Result<String> {
4040
);
4141

4242
for line in LinesWithEndings::from(code) {
43-
if line.len() > LINE_SIZE_LIMIT {
43+
if line.len() > PER_LINE_BYTE_LENGTH_LIMIT {
4444
return Err(LimitsExceeded.into());
4545
}
4646
html_generator.parse_html_for_line_which_includes_newline(line)?;
@@ -81,7 +81,8 @@ pub fn with_lang(lang: Option<&str>, code: &str) -> String {
8181
#[cfg(test)]
8282
mod tests {
8383
use super::{
84-
select_syntax, try_with_lang, with_lang, LimitsExceeded, CODE_SIZE_LIMIT, LINE_SIZE_LIMIT,
84+
select_syntax, try_with_lang, with_lang, LimitsExceeded, PER_LINE_BYTE_LENGTH_LIMIT,
85+
TOTAL_CODE_BYTE_LENGTH_LIMIT,
8586
};
8687

8788
#[test]
@@ -106,13 +107,13 @@ mod tests {
106107
.unwrap_err()
107108
.is::<LimitsExceeded>()
108109
};
109-
assert!(is_limited("a\n".repeat(CODE_SIZE_LIMIT)));
110-
assert!(is_limited("aa".repeat(LINE_SIZE_LIMIT)));
110+
assert!(is_limited("a\n".repeat(TOTAL_CODE_BYTE_LENGTH_LIMIT)));
111+
assert!(is_limited("aa".repeat(PER_LINE_BYTE_LENGTH_LIMIT)));
111112
}
112113

113114
#[test]
114115
fn limited_escaped() {
115-
let text = "<p>\n".to_string() + "aa".repeat(LINE_SIZE_LIMIT).as_str();
116+
let text = "<p>\n".to_string() + "aa".repeat(PER_LINE_BYTE_LENGTH_LIMIT).as_str();
116117
let highlighted = with_lang(Some("toml"), &text);
117118
assert!(highlighted.starts_with("&lt;p&gt;\n"));
118119
}

0 commit comments

Comments
 (0)