1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 08:27:22 +03:00

Fix the local(Test Test) syntax in @font-face src

Related to #487.
This commit is contained in:
Guillaume Ayoub 2017-07-20 17:04:46 +02:00
parent e0acecb4db
commit 1fd38bdc7b
2 changed files with 28 additions and 1 deletions

View File

@ -56,7 +56,7 @@ def font_family(tokens, allow_spaces=False):
"""``font-family`` descriptor validation.""" """``font-family`` descriptor validation."""
allowed_types = ['ident'] allowed_types = ['ident']
if allow_spaces: if allow_spaces:
allowed_types.append('S') allowed_types.append('whitespace')
if len(tokens) == 1 and tokens[0].type == 'string': if len(tokens) == 1 and tokens[0].type == 'string':
return tokens[0].value return tokens[0].value
if tokens and all(token.type in allowed_types for token in tokens): if tokens and all(token.type in allowed_types for token in tokens):

View File

@ -56,6 +56,33 @@ def test_font_face():
assert font_weight == ('font_weight', 200) assert font_weight == ('font_weight', 200)
assert font_stretch == ('font_stretch', 'condensed') assert font_stretch == ('font_stretch', 'condensed')
stylesheet = tinycss2.parse_stylesheet(
'@font-face {'
' font-family: Gentium Hard;'
' src: local();'
'}')
at_rule, = stylesheet
assert at_rule.at_keyword == 'font-face'
font_family, src = list(preprocess_descriptors(
'http://weasyprint.org/foo/',
tinycss2.parse_declaration_list(at_rule.content)))
assert font_family == ('font_family', 'Gentium Hard')
assert src == ('src', [('local', None)])
# See bug #487
stylesheet = tinycss2.parse_stylesheet(
'@font-face {'
' font-family: Gentium Hard;'
' src: local(Gentium Hard);'
'}')
at_rule, = stylesheet
assert at_rule.at_keyword == 'font-face'
font_family, src = list(preprocess_descriptors(
'http://weasyprint.org/foo/',
tinycss2.parse_declaration_list(at_rule.content)))
assert font_family == ('font_family', 'Gentium Hard')
assert src == ('src', [('local', 'Gentium Hard')])
def test_bad_font_face(): def test_bad_font_face():
"""Test bad ``font-face`` rules.""" """Test bad ``font-face`` rules."""