-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Filters::spacelessHtml() Add support for use <script> as link to JS #196
base: master
Are you sure you want to change the base?
Conversation
{ | ||
if ($phase & PHP_OUTPUT_HANDLER_START) { | ||
$s = ltrim($s); | ||
} | ||
if ($phase & PHP_OUTPUT_HANDLER_FINAL) { | ||
$s = rtrim($s); | ||
} | ||
return preg_replace_callback( | ||
$return = (string) preg_replace_callback( // Other cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why (string)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because PhpStorm hint to me new type can be returned in future. For example null
in case of error.
'#[ \t\r\n]+|<(/)?(textarea|pre|script)(?=\W)#si', | ||
function ($m) use (&$strip) { | ||
static function (array $m) use (&$strip): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why static
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP does not have to create a new instance every time.
}, | ||
$s | ||
); | ||
$return = (string) preg_replace_callback( // <script> for include JS file | ||
'/<script\s*([^>]+?)>(?:\s*)<\/script>/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this regexp work with input like <script title="> <\/script>">
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This input is not supported now. I'll try to come up with a better solution.
1a297fd
to
8fb996f
Compare
4d5343b
to
6edda93
Compare
090695a
to
dba2a60
Compare
d3ff96d
to
47c1926
Compare
942f9b1
to
753a2fc
Compare
8d92896
to
1267554
Compare
ee646d6
to
b80c3a6
Compare
6c48587
to
bd46751
Compare
6baf2c5
to
4db7a55
Compare
In case of
block y
generate too long code:Old return:
New return:
I think this feature is absolutely safe, because if you have empty
<script>
body you can safely replace repeating whitespaces to single whitespace.Real case in real website:
Thanks.