Skip to content

Commit

Permalink
Fixed invalid escape sequences.
Browse files Browse the repository at this point in the history
Note that only some are for regular expressions (only one of them being reported as having an invalid escape sequence).
The others are strings (well, bytes) used in a different way.

It is very hard to see whether the magic mimetype changes are okay.
For the first one, starting with 8BPS, for x-psd, I have found it in /usr/share/mime on Ubuntu 18.04,
but even then I am not entirely sure it is correct.

I could not find the others in there, but they do seem safer, as they are actually the same.
For example:

    b'<smil\>' == br'<smil\>'
  • Loading branch information
mauritsvanrees committed Sep 9, 2020
1 parent c16094a commit d241e79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Products/MimetypesRegistry/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import six


EMACS_ENCODING_RGX = re.compile('[^#]*[#\s]*-\*-\s*coding: ([^\s]*)\s*-\*-\s*')
VIM_ENCODING_RGX = re.compile('[^#]*[#\s]*vim:fileencoding=\s*([^\s]*)\s*')
XML_ENCODING_RGX = re.compile('<\?xml version=[^\s]*\s*encoding=([^\s]*)\s*\?>') # noqa
CHARSET_RGX = re.compile('charset=([^\s"]*)')
EMACS_ENCODING_RGX = re.compile(r'[^#]*[#\s]*-\*-\s*coding: ([^\s]*)\s*-\*-\s*')
VIM_ENCODING_RGX = re.compile(r'[^#]*[#\s]*vim:fileencoding=\s*([^\s]*)\s*')
XML_ENCODING_RGX = re.compile(r'<\?xml version=[^\s]*\s*encoding=([^\s]*)\s*\?>')
CHARSET_RGX = re.compile(r'charset=([^\s"]*)')


def guess_encoding(buffer):
Expand Down
18 changes: 9 additions & 9 deletions Products/MimetypesRegistry/mime_types/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
[0,
'string',
'=',
b'8BPS\ \ \000\000\000\000 &0xffffffff0000ffffffff',
br'8BPS \000\000\000\000 &0xffffffff0000ffffffff',
'image/x-psd'],
[0, 'string', '=', b'#LyX', 'text/x-lyx'],
[0, 'string', '=', b'DCMw', 'application/dicom'],
Expand All @@ -122,12 +122,12 @@
[0,
'string',
'=',
b'<!DOCTYPE NETSCAPE-Bookmark-file-1\>',
br'<!DOCTYPE NETSCAPE-Bookmark-file-1\>',
'application/x-mozilla-bookmarks'],
[0,
'string',
'=',
b'<!DOCTYPE NETSCAPE-Bookmark-file-1\>',
br'<!DOCTYPE NETSCAPE-Bookmark-file-1\>',
'application/x-netscape-bookmarks'],
[0,
'string',
Expand All @@ -137,8 +137,8 @@
[0, 'string', '=', b'<!DOCTYPE svg', 'image/svg+xml'],
[0, 'string', '=', b'<svg', 'image/svg+xml'],
[0, 'string', '=', b'<?php', 'application/x-php'],
[0, 'string', '=', b'<smil\>', 'application/smil'],
[0, 'string', '=', b'<SMIL\>', 'application/smil'],
[0, 'string', '=', br'<smil\>', 'application/smil'],
[0, 'string', '=', br'<SMIL\>', 'application/smil'],
[0, 'string', '=', b'<!DOCTYPE HTML', 'text/html'],
[0, 'string', '=', b'<!DOCTYPE html', 'text/html'],
[0, 'string', '=', b'<!doctype html', 'text/html'],
Expand All @@ -152,7 +152,7 @@
[0, 'string', '=', b'<HTML', 'text/html'],
[0, 'string', '=', b'<dia:diagram', 'application/x-dia-diagram'],
[0, 'string', '=', b'<abiword', 'application/x-abiword'],
[0, 'string', '=', b'<\!DOCTYPE abiword', 'application/x-abiword'],
[0, 'string', '=', br'<\!DOCTYPE abiword', 'application/x-abiword'],
[0, 'string', '=', b'gmr:Workbook', 'application/x-gnumeric'],
[0, 'string', '=', b'<?xml', 'text/xml'],
[0, 'string', '=', b'{\\rtf', 'application/rtf'],
Expand Down Expand Up @@ -188,8 +188,8 @@
[0, 'belong', '=', b'0x000001b3', 'video/mpeg'],
[0, 'string', '=', b'RIFF', 'audio/x-riff'],
[0, 'string', '=', b'OggS ', 'audio/ogg'],
[0, 'string', '=', b'pnm:\/\/', 'audio/vnd.rn-realaudio'],
[0, 'string', '=', b'rtsp:\/\/', 'audio/vnd.rn-realaudio'],
[0, 'string', '=', br'pnm://', 'audio/vnd.rn-realaudio'],
[0, 'string', '=', br'rtsp://', 'audio/vnd.rn-realaudio'],
[0, 'string', '=', b'SIT!', 'application/x-stuffit'],
[0, 'string', '=', b'\312\376\272\276', 'application/x-java'],
[0, 'string', '=', b'Joy!', 'application/x-pef-executable'],
Expand Down Expand Up @@ -239,7 +239,7 @@
[0, 'string', '=', b'\xff\x46\x4f\x4e', 'application/x-font-dos'],
[7, 'string', '=', b'\x00\x45\x47\x41', 'application/x-font-dos'],
[7, 'string', '=', b'\x00\x56\x49\x44', 'application/x-font-dos'],
[0, 'string', '=', b'\<MakerScreenFont', 'application/x-font-framemaker'],
[0, 'string', '=', br'\<MakerScreenFont', 'application/x-font-framemaker'],
[0, 'string', '=', b'\000\001\000\000\000', 'application/x-font-ttf'],
[1, 'string', '=', b'WPC', 'application/x-wordperfect'],
[0, 'string', '=', b'ID;', 'text/spreadsheet'],
Expand Down
2 changes: 2 additions & 0 deletions news/3130.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed invalid escape sequences.
[maurits]

0 comments on commit d241e79

Please sign in to comment.