Skip to content

Commit 2687c8d

Browse files
committed
Added a workaround for libmagic mislabelling plain text content with a line beginning with 'virtual' as text/x-c++.
- Legacy-Id: 14586
1 parent fbb4b44 commit 2687c8d

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

ietf/meeting/tests_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ def test_upload_minutes_agenda(self):
16351635
q = PyQuery(r.content)
16361636
self.assertTrue(q('form .has-error'))
16371637

1638-
test_file = StringIO('this is some text for a test')
1638+
test_file = StringIO(u'This is some text for a test, with the word\nvirtual at the beginning of a line.')
16391639
test_file.name = "not_really.txt"
16401640
r = self.client.post(url,dict(file=test_file,apply_to_all=False))
16411641
self.assertEqual(r.status_code, 302)

ietf/utils/validators.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ def validate_file_size(file):
7373

7474
def validate_mime_type(file, valid):
7575
file.open()
76-
mime_type, encoding = get_mime_type(file.read())
76+
raw = file.read()
77+
mime_type, encoding = get_mime_type(raw)
78+
# work around mis-identification of text where a line has 'virtual' as
79+
# the first word:
80+
if mime_type == 'text/x-c++' and re.search('(?m)^virtual\s', raw):
81+
mod = raw.replace(str('virtual'), str(' virtual'))
82+
mime_type, encoding = get_mime_type(mod)
7783
if not mime_type in valid:
7884
raise ValidationError('Found content with unexpected mime type: %s. Expected one of %s.' %
7985
(mime_type, ', '.join(valid) ))

0 commit comments

Comments
 (0)