Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test vector for no whitespace after semicolon in mimetype #214

Merged
merged 2 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions flex/loading/common/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
# top-level type name / [ tree. ] subtype name [ +suffix ] [ ; parameters ]
MIMETYPE_PATTERN = (
'^'
'(application|audio|example|image|message|model|multipart|text|video)' # top-level type name
# https://www.iana.org/assignments/media-types/media-types.xhtml
'(application|audio|example|font|image|message|model|multipart|text|video)' # media type
'/'
'(vnd(\.[-a-zA-Z0-9]+)*\.)?' # vendor tree
'([-a-zA-Z0-9]+)' # media type
'(\+(xml|json|ber|der|fastinfoset|wbxml|zip))?'
'([-a-zA-Z0-9]+)' # media subtype
# https://www.iana.org/assignments/media-type-structured-suffix/media-type-structured-suffix.xml
'(\+(xml|json|ber|cbor|der|fastinfoset|wbxml|zip|tlv|json-seq|sqlite3|jwt|gzip))?'
'((; ?[-a-zA-Z0-9]+=(([-\.a-zA-Z0-9]+)|(("|\')[-\.a-zA-Z0-9]+("|\'))))+)?' # parameters
'$'
)
Expand Down
58 changes: 49 additions & 9 deletions tests/loading/schema/test_mimetype_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,57 @@ def test_mimetype_invalid_for_non_array_value(value):
@pytest.mark.parametrize(
'value',
(
# different media types with simple subtypes
['application/json'],
['application/json'],
['image/svg+xml'],
['application/vnd.oasis.opendocument.text'],
['text/plain; charset=utf-8'],
['video/mp4'],
['video/mp4; codecs="avc1.640028"'],
["video/mp4; codecs='avc1.640028'"],
['application/xhtml+xml'],
['audio/basic'],
['font/collection'],
['example/json'],
['image/png'],
['application/vnd.ms-excel'],
['message/http'],
['model/stl'],
['multipart/encrypted'],
['text/html'],
['video/ogg'],
['video/mp4'],
# different complex subtypes
['application/1d-interleaved-parityfec'], # dashes in subtype
['video/JPEG'], # uppercase
['video/SMPTE292M'], # uppercase and numbers
['video/smpte291'], # lowercase and numbers
['video/CelB'], # mixed-case
# vendor subtypes
['application/vnd.apple.pages'], # simple vendor
['application/vnd.oasis.opendocument.text'], # multiple vendor
# suffixes
['application/xhtml+xml'], # common
['image/svg+xml'], # common
['application/calendar+json'],
['application/geo+json'],
['application/jose+json'],
['application/json-patch+json'],
['application/jwk-set+json'],
['application/jwk+json'],
['application/vcard+json'],
['application/senml+cbor'],
['application/dssc+der'],
['application/soap+fastinfoset'],
['application/vnd.nokia.pcd+wbxml'], # wbxml only occurs with vendor
['application/epub+zip'],
['application/vnd.oma.lwm2m+tlv'], # only registered use
['application/geo+json-seq'], # only registered use
['application/geopackage+sqlite3'], # only registered use
['application/secevent+jwt'], # only registered use
['application/tlsrpt+gzip'], # only registered use
# complex cases
['application/3gpdash-qoe-report+xml'], # dashes in subtype
['application/vnd.api+json'], # vendor and suffix
['application/vnd.bbf.usp.msg+json'], # multiple vendor tokens
['application/vnd.ms-excel'], # vendor with dashes
['application/vnd.collabio.xodocuments.spreadsheet-template'], # long vendor
['text/plain; charset=utf-8'], # unquoted parameter with space
['text/plain;charset=utf-8'], # unquoted parameter without space
['video/mp4; codecs="avc1.640028"'], # double quoted parameter
["video/mp4; codecs='avc1.640028'"], # single quoted parameter
)
)
def test_mimetype_with_valid_values(value):
Expand Down