Added a workaround for libmagic mislabelling plain text content with a line beginning with 'virtual' as text/x-c++.
- Legacy-Id: 14586
This commit is contained in:
parent
fbb4b4447f
commit
2687c8d839
|
@ -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)
|
||||
|
|
|
@ -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) ))
|
||||
|
|
Loading…
Reference in a new issue