Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
ed3b05bc
Commit
ed3b05bc
authored
8 months ago
by
Dieter Holvoet
Browse files
Options
Downloads
Patches
Plain Diff
Add 2990907-24.patch
parent
e5653c11
No related branches found
No related tags found
1 merge request
!9280
Add 2990907-24.patch
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Asset/JsOptimizer.php
+1
-1
1 addition, 1 deletion
core/lib/Drupal/Core/Asset/JsOptimizer.php
core/tests/Drupal/Tests/Core/Asset/JsOptimizerUnitTest.php
+29
-0
29 additions, 0 deletions
core/tests/Drupal/Tests/Core/Asset/JsOptimizerUnitTest.php
with
30 additions
and
1 deletion
core/lib/Drupal/Core/Asset/JsOptimizer.php
+
1
−
1
View file @
ed3b05bc
...
...
@@ -79,7 +79,7 @@ public function optimize(array $js_asset) {
*/
public
function
clean
(
$contents
)
{
// Remove JS source and source mapping URLs or these may cause 404 errors.
$contents
=
preg_replace
(
'
/\/\/(#|@)\s(sourceURL|source
MappingURL)=\s*(\S
*?
)\s*
$/m
'
,
''
,
$contents
);
$contents
=
preg_replace
(
'
~//[#@]\s(source(?:
Mapping
)?
URL)=\s*(\S
+
)\s*
~
'
,
''
,
$contents
);
return
$contents
;
}
...
...
This diff is collapsed.
Click to expand it.
core/tests/Drupal/Tests/Core/Asset/JsOptimizerUnitTest.php
+
29
−
0
View file @
ed3b05bc
...
...
@@ -77,6 +77,35 @@ public function testClean($js_asset, $expected): void {
$this
->
assertEquals
(
$expected
,
$this
->
optimizer
->
clean
(
$js_asset
));
}
/**
* Tests that the javascript may be cleaned without backtracking.
*/
public
function
testCleanWithRecursionLimit
()
{
// Specify a hard backtracking limit.
ini_set
(
'pcre.backtrack_limit'
,
100
);
$backtrack_limit
=
(
int
)
ini_get
(
'pcre.backtrack_limit'
);
$this
->
assertEquals
(
100
,
$backtrack_limit
);
$script
=
<<<JS
(function($) { "use strict"; })
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
JS;
// Generate a source map URL that would exceed the backtrack limit.
$script
.
=
str_repeat
(
'x'
,
$backtrack_limit
);
// Add an empty space after the sourcemap, followed by other
// miscellaneous code.
$script
.
=
<<<JS
// I appear after the sourcemap URL.
(function($) { "use strict"; console.log('Hello'); })
JS;
$expected_script
=
<<<JS
(function($) { "use strict"; })
// I appear after the sourcemap URL.
(function($) { "use strict"; console.log('Hello'); })
JS;
$this
->
assertEquals
(
$expected_script
,
$this
->
optimizer
->
clean
(
$script
));
}
/**
* Provides data for the JS asset optimize test.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment