tbela99 / css

A CSS parser and minifier and sourcemap generator written in PHP
Other
14 stars 1 forks source link

@font-face "src" - missed ' #39

Closed Cruglk closed 3 years ago

Cruglk commented 3 years ago

$test = "@font-face{font-family:'CenturyGothic';src:url('/CenturyGothic.woff') format('woff');font-weight:400;}";

Result:

@font-face { font-family: CenturyGothic; font-weight: 400; src: url(/CenturyGothic.woff) format(woff) }

Correctly:

@font-face { font-family: CenturyGothic; font-weight: 400; src: url(/CenturyGothic.woff) format('woff') }

tbela99 commented 3 years ago

Can you please specify the context? did you test in a web browser? if yes, which one?

Thanks

Cruglk commented 3 years ago

@tbela99, Example. Full HTML-code. The font is displayed:

<style>@font-face{font-family:'CenturyGothic';src:url('https://static.tildacdn.com/tild3266-3633-4465-b435-326361353130/CenturyGothic.woff') format('woff');font-weight:400;}.text{font-family:'CenturyGothic';}
</style><div class="text">Test</div>

And test. The font is not displayed.

<?php require 'vendor/autoload.php'; 
use \TBela\CSS\Parser;
use \TBela\CSS\Renderer;
$test = "@font-face{font-family:'CenturyGothic';src:url('https://static.tildacdn.com/tild3266-3633-4465-b435-326361353130/CenturyGothic.woff') format('woff');font-weight:400;}*{font-family:'CenturyGothic';}";
$parser = new Parser($test);
$element = $parser->parse();
$css = (string)$element;
$renderer = new Renderer([
    'compress' => false,
    'css_level' => 4,
    'allow_duplicate_declarations' => false
]);
$css = $renderer->render($element);
echo '<style>'.$css.'</style>';`
Cruglk commented 3 years ago

https://jigsaw.w3.org/css-validator/validator.html.en#validate_by_input

@font-face {
font-family: CenturyGothic;
src: url(/fonts/CenturyGothic.woff) format('woff');
font-weight: 400;
}

And:

@font-face {
font-family: CenturyGothic;
src: url(/fonts/CenturyGothic.woff) format(woff);
font-weight: 400;
}

Ungly fix. CssString.php:

if(preg_match('#woff#', $data->value)){
    $data->q = '';
}else{
    $data->value = substr($data->value, 1, -1);
}
if (preg_match('#^[\w_-]+$#', $data->value)) {
    $data->q = '';
}
tbela99 commented 3 years ago

all issues are now fixed and will be merged soon into the master branch.

Thanks for your reports!