-
-
Notifications
You must be signed in to change notification settings - Fork 113
Filters::spacelessHtml() Add support for use <script> as link to JS #196
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
base: master
Are you sure you want to change the base?
Conversation
| $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.
| $return = (string) preg_replace_callback( // Other cases | ||
| '#[ \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
0716cd8 to
a24efec
Compare
25ca040 to
271b3a6
Compare
d6efe40 to
51e3c9b
Compare
8274544 to
1d959eb
Compare
eb0f931 to
c4e3e89
Compare
In case of
block ygenerate too long code:{block x|strip} Lorem ipsum dolor sit amet, <script src="main.js"></script> consectetur adipiscing elit. {/block} ------ {block y|strip} Lorem ipsum dolor sit amet, <script src="main.js" title="value" ></script> consectetur adipiscing elit. {/block}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.