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

Allow forward slashes inside integrity attribute #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/Middleware/RemoveComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class RemoveComments extends PageSpeed
{
const REGEX_MATCH_JS_AND_CSS_COMMENTS = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\")\/\/.*))/';
const REGEX_MATCH_JS_AND_CSS_COMMENTS = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\"|[integrity])\/\/.*))/';
const REGEX_MATCH_HTML_COMMENTS = '/<!--[^]><!\[](.*?)[^\]]-->/s';

public function apply($buffer)
Expand Down
2 changes: 2 additions & 0 deletions tests/Boilerplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ <h1>Test Background Image</h1>

<script src="https://github.com/renatomarinho/laravel-page-speed/test/Boilerplate/js/vendor/modernizr-3.5.0.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>

<script>window.jQuery || document.write('<script src="js/vendor/jquery-3.2.1.min.js"><\/script>')</script>
<script src="https://github.com/renatomarinho/laravel-page-speed/test/Boilerplate/js/plugins.js" data-pagespeed-no-defer></script>
<script src="https://github.com/renatomarinho/laravel-page-speed/test/Boilerplate/js/main.js"></script>
Expand Down
5 changes: 5 additions & 0 deletions tests/Middleware/RemoveCommentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,10 @@ public function testRemoveJsComments()
$this->assertStringContainsString("console.log('Laravel');", $this->response->getContent());
$this->assertStringContainsString("console.log('Page');", $this->response->getContent());
$this->assertStringContainsString("console.log('Speed!');", $this->response->getContent());

$this->assertStringContainsString(
'<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>',
$this->response->getContent()
);
}
}