diff --git a/ietf/meeting/tests_views.py b/ietf/meeting/tests_views.py index ed05853c0..09af58d67 100644 --- a/ietf/meeting/tests_views.py +++ b/ietf/meeting/tests_views.py @@ -1635,7 +1635,7 @@ class MaterialsTests(TestCase): q = PyQuery(r.content) self.assertTrue(q('form .has-error')) - test_file = StringIO('this is some text for a test') + test_file = StringIO(u'This is some text for a test, with the word\nvirtual at the beginning of a line.') test_file.name = "not_really.txt" r = self.client.post(url,dict(file=test_file,apply_to_all=False)) self.assertEqual(r.status_code, 302) diff --git a/ietf/utils/validators.py b/ietf/utils/validators.py index 440c43d99..f98f8065a 100644 --- a/ietf/utils/validators.py +++ b/ietf/utils/validators.py @@ -73,7 +73,13 @@ def validate_file_size(file): def validate_mime_type(file, valid): file.open() - mime_type, encoding = get_mime_type(file.read()) + raw = file.read() + mime_type, encoding = get_mime_type(raw) + # work around mis-identification of text where a line has 'virtual' as + # the first word: + if mime_type == 'text/x-c++' and re.search('(?m)^virtual\s', raw): + mod = raw.replace(str('virtual'), str(' virtual')) + mime_type, encoding = get_mime_type(mod) if not mime_type in valid: raise ValidationError('Found content with unexpected mime type: %s. Expected one of %s.' % (mime_type, ', '.join(valid) ))