Skip whitespace for html view

In some cases (such as the new coverage report) there is leading
whitespace before the <html> tag. Skip these lines when trying to
detect if we should escape any content.

This makes os-loganlayze lossy whereby it'll ignore leading whitespace
in html files.

Change-Id: Ie7b183dfa78f58f0b39339ba41850393b248b872
This commit is contained in:
Joshua Hesketh 2015-09-23 10:47:31 -05:00
parent e185cd0dd3
commit 082d0b942a
4 changed files with 24 additions and 1 deletions

View File

View File

@ -1,3 +1,9 @@
<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
Should detect HTML even though there is leading whitespace.
</html>

View File

@ -50,3 +50,12 @@ class TestViews(base.TestCase):
# Move the generator so that the is_html flag is set
i.next()
self.assertTrue(html_view.is_html)
def test_empty_file_html_view(self):
gen = self.get_generator('empty.html')
html_view = osview.HTMLView(gen)
self.assertFalse(html_view.is_html)
full_text = ""
for i in html_view:
full_text += i
self.assertEqual("", full_text)

View File

@ -165,7 +165,15 @@ class HTMLView(collections.Iterable):
def __iter__(self):
igen = (x for x in self.filter_generator)
first_line = next(igen)
# Grab the first non-empty line
first_line = None
for i in igen:
if i.line:
first_line = i
break
if not first_line:
# The file must be empty
return
self._discover_html(first_line.line)
if not self.is_html: