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:
parent
e185cd0dd3
commit
082d0b942a
|
@ -1,3 +1,9 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
|
Should detect HTML even though there is leading whitespace.
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -50,3 +50,12 @@ class TestViews(base.TestCase):
|
||||||
# Move the generator so that the is_html flag is set
|
# Move the generator so that the is_html flag is set
|
||||||
i.next()
|
i.next()
|
||||||
self.assertTrue(html_view.is_html)
|
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)
|
||||||
|
|
|
@ -165,7 +165,15 @@ class HTMLView(collections.Iterable):
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
igen = (x for x in self.filter_generator)
|
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)
|
self._discover_html(first_line.line)
|
||||||
|
|
||||||
if not self.is_html:
|
if not self.is_html:
|
||||||
|
|
Loading…
Reference in New Issue