@@ -6,8 +6,8 @@ use syntect::{
6
6
util:: LinesWithEndings ,
7
7
} ;
8
8
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 ;
11
11
12
12
#[ derive( Debug , thiserror:: Error ) ]
13
13
#[ error( "the code exceeded a highlighting limit" ) ]
@@ -29,7 +29,7 @@ static SYNTAXES: Lazy<SyntaxSet> = Lazy::new(|| {
29
29
} ) ;
30
30
31
31
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 {
33
33
return Err ( LimitsExceeded . into ( ) ) ;
34
34
}
35
35
@@ -40,7 +40,7 @@ fn try_with_syntax(syntax: &SyntaxReference, code: &str) -> Result<String> {
40
40
) ;
41
41
42
42
for line in LinesWithEndings :: from ( code) {
43
- if line. len ( ) > LINE_SIZE_LIMIT {
43
+ if line. len ( ) > PER_LINE_BYTE_LENGTH_LIMIT {
44
44
return Err ( LimitsExceeded . into ( ) ) ;
45
45
}
46
46
html_generator. parse_html_for_line_which_includes_newline ( line) ?;
@@ -81,7 +81,8 @@ pub fn with_lang(lang: Option<&str>, code: &str) -> String {
81
81
#[ cfg( test) ]
82
82
mod tests {
83
83
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 ,
85
86
} ;
86
87
87
88
#[ test]
@@ -106,13 +107,13 @@ mod tests {
106
107
. unwrap_err ( )
107
108
. is :: < LimitsExceeded > ( )
108
109
} ;
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 ) ) ) ;
111
112
}
112
113
113
114
#[ test]
114
115
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 ( ) ;
116
117
let highlighted = with_lang ( Some ( "toml" ) , & text) ;
117
118
assert ! ( highlighted. starts_with( "<p>\n " ) ) ;
118
119
}
0 commit comments