From cfd754d8929db49a699f8e18ab7ab1cb78354a49 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 25 May 2019 14:32:24 +0200 Subject: [PATCH 1/3] Fix theme-checker failure --- src/librustdoc/theme.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 7a0ccf6975f8c..b3196217adc4d 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -110,7 +110,7 @@ fn load_css_events(v: &[u8]) -> Vec { let mut pos = 0; let mut events = Vec::with_capacity(100); - while pos < v.len() - 1 { + while pos + 1 < v.len() { match v[pos] { b'/' if pos + 1 < v.len() && v[pos + 1] == b'*' => { events.push(Events::StartComment(pos)); From 165a95b37151105c0822bc84d0939439f7b96b06 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 May 2019 00:02:44 +0200 Subject: [PATCH 2/3] Add test for empty css file check --- src/librustdoc/theme.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index b3196217adc4d..48142de95a9be 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -366,4 +366,10 @@ a { get_differences(&other, &against, &mut ret); assert_eq!(ret, vec![" Missing \"c\" rule".to_owned()]); } + + #[test] + fn check_empty_css() { + let events = load_css_events(&[]); + assert_eq!(events.len(), 0); + } } From 640bdbdb1da73cde39c33fc2be3cddd3b71389b0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 May 2019 15:25:01 +0200 Subject: [PATCH 3/3] Improve theme checker by removing unneeded conditions --- src/librustdoc/theme.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 48142de95a9be..7220a05df47e6 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -103,7 +103,7 @@ fn is_line_comment(pos: usize, v: &[u8], events: &[Events]) -> bool { if let Some(&Events::StartComment(_)) = events.last() { return false; } - pos + 1 < v.len() && v[pos + 1] == b'/' + v[pos + 1] == b'/' } fn load_css_events(v: &[u8]) -> Vec { @@ -112,7 +112,7 @@ fn load_css_events(v: &[u8]) -> Vec { while pos + 1 < v.len() { match v[pos] { - b'/' if pos + 1 < v.len() && v[pos + 1] == b'*' => { + b'/' if v[pos + 1] == b'*' => { events.push(Events::StartComment(pos)); pos += 1; } @@ -123,7 +123,7 @@ fn load_css_events(v: &[u8]) -> Vec { b'\n' if previous_is_line_comment(&events) => { events.push(Events::EndComment(pos)); } - b'*' if pos + 1 < v.len() && v[pos + 1] == b'/' => { + b'*' if v[pos + 1] == b'/' => { events.push(Events::EndComment(pos + 2)); pos += 1; } @@ -264,9 +264,11 @@ pub fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec) } } -pub fn test_theme_against>(f: &P, against: &CssPath, diag: &Handler) - -> (bool, Vec) -{ +pub fn test_theme_against>( + f: &P, + against: &CssPath, + diag: &Handler, +) -> (bool, Vec) { let data = try_something!(fs::read(f), diag, (false, vec![])); let paths = load_css_paths(&data); let mut ret = vec![]; @@ -372,4 +374,10 @@ a { let events = load_css_events(&[]); assert_eq!(events.len(), 0); } + + #[test] + fn check_invalid_css() { + let events = load_css_events(b"*"); + assert_eq!(events.len(), 0); + } }