Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
fe5a50c3
Commit
fe5a50c3
authored
11 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
fix single line comments in CSS compression
double slashes in url() always have to be ignored
parent
0499ebed
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_test/tests/lib/exe/css_css_compress.test.php
+23
-9
23 additions, 9 deletions
_test/tests/lib/exe/css_css_compress.test.php
lib/exe/css.php
+43
-1
43 additions, 1 deletion
lib/exe/css.php
with
66 additions
and
10 deletions
_test/tests/lib/exe/css_css_compress.test.php
+
23
−
9
View file @
fe5a50c3
...
...
@@ -10,33 +10,47 @@ class css_css_compress_test extends DokuWikiTest {
* line *test*
* check
*/'
;
$this
->
assertEquals
(
css_compress
(
$text
)
,
''
);
$this
->
assertEquals
(
''
,
css_compress
(
$text
));
}
function
test_mlcom2
(){
$text
=
'#comment/* */ {
color: lime;
}'
;
$this
->
assertEquals
(
css_compress
(
$text
),
'#comment/* */{color:lime;}'
);
$this
->
assertEquals
(
'#comment/* */{color:lime;}'
,
css_compress
(
$text
)
);
}
function
test_slcom1
(){
$text
=
'// this is a comment'
;
$this
->
assertEquals
(
css_compress
(
$text
)
,
''
);
$this
->
assertEquals
(
''
,
css_compress
(
$text
));
}
function
test_slcom2
(){
$text
=
'#foo {
color: lime; // another comment
}'
;
$this
->
assertEquals
(
css_compress
(
$text
),
'#foo{color:lime;}'
);
$this
->
assertEquals
(
'#foo{color:lime;}'
,
css_compress
(
$text
)
);
}
function
test_slcom3
(){
$text
=
'#foo {
background-image: url(http://foo.bar/baz.jpg);
background-image: url(http://foo.bar/baz.jpg);
// this is a comment
}'
;
$this
->
assertEquals
(
css_compress
(
$text
),
'#foo{background-image:url(http://foo.bar/baz.jpg);}'
);
$this
->
assertEquals
(
'#foo{background-image:url(http://foo.bar/baz.jpg);}'
,
css_compress
(
$text
));
}
function
test_slcom4
(){
$text
=
'#foo {
background-image: url(http://foo.bar/baz.jpg); background-image: url(http://foo.bar/baz.jpg); // this is a comment
}'
;
$this
->
assertEquals
(
'#foo{background-image:url(http://foo.bar/baz.jpg);background-image:url(http://foo.bar/baz.jpg);}'
,
css_compress
(
$text
));
}
function
test_slcom5
(){
$text
=
'#foo {
background-image: url(http://foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented
}'
;
$this
->
assertEquals
(
'#foo{background-image:url(http://foo.bar/baz.jpg);}'
,
css_compress
(
$text
));
}
function
test_hack
(){
...
...
@@ -44,7 +58,7 @@ class css_css_compress_test extends DokuWikiTest {
/* \\*/
display: inline;
/* */'
;
$this
->
assertEquals
(
css_compress
(
$text
),
'/* \\*/display:inline;/* */'
);
$this
->
assertEquals
(
'/* \\*/display:inline;/* */'
,
css_compress
(
$text
)
);
}
function
test_hack2
(){
...
...
@@ -54,12 +68,12 @@ class css_css_compress_test extends DokuWikiTest {
height: 450px;
}
/**/'
;
$this
->
assertEquals
(
css_compress
(
$text
),
'/*\\*/* html .page{height:450px;}/**/'
);
$this
->
assertEquals
(
'/*\\*/* html .page{height:450px;}/**/'
,
css_compress
(
$text
)
);
}
function
test_nl1
(){
$text
=
"a
{
left:20px;\ntop:20px
}
"
;
$this
->
assertEquals
(
css_compress
(
$text
),
'a{left:20px;top:20px}'
);
$this
->
assertEquals
(
'a{left:20px;top:20px}'
,
css_compress
(
$text
)
);
}
function
test_shortening
()
{
...
...
This diff is collapsed.
Click to expand it.
lib/exe/css.php
+
43
−
1
View file @
fe5a50c3
...
...
@@ -552,7 +552,7 @@ function css_compress($css){
$css
=
preg_replace_callback
(
'#(/\*)(.*?)(\*/)#s'
,
'css_comment_cb'
,
$css
);
//strip (incorrect but common) one line comments
$css
=
preg_replace
(
'/(?<!:)\/\/.*$/m'
,
'
'
,
$css
);
$css
=
preg_replace
_callback
(
'/^.*\/\/.*$/m'
,
'css_onelinecomment_cb
'
,
$css
);
// strip whitespaces
$css
=
preg_replace
(
'![\r\n\t ]+!'
,
' '
,
$css
);
...
...
@@ -588,4 +588,46 @@ function css_comment_cb($matches){
return
$matches
[
0
];
}
/**
* Callback for css_compress()
*
* Strips one line comments but makes sure it will not destroy url() constructs with slashes
*
* @param $matches
* @return string
*/
function
css_onelinecomment_cb
(
$matches
)
{
$line
=
$matches
[
0
];
$out
=
''
;
$i
=
0
;
$len
=
strlen
(
$line
);
while
(
$i
<
$len
){
$nextcom
=
strpos
(
$line
,
'//'
,
$i
);
$nexturl
=
stripos
(
$line
,
'url('
,
$i
);
if
(
$nextcom
===
false
)
{
// no more comments, we're done
$out
.
=
substr
(
$line
,
$i
,
$len
-
$i
);
break
;
}
if
(
$nexturl
===
false
)
{
// no url anymore, strip comment and be done
$out
.
=
substr
(
$line
,
$i
,
$nextcom
-
$i
);
break
;
}
if
(
$nextcom
<
$nexturl
)
{
// that comment comments out the url
$out
.
=
substr
(
$line
,
$i
,
$len
-
$i
);
break
;
}
// we have an upcoming url
$urlclose
=
strpos
(
$line
,
')'
,
$nexturl
);
$out
.
=
substr
(
$line
,
$i
,
$urlclose
-
$i
);
$i
=
$urlclose
;
}
return
$out
;
}
//Setup VIM: ex: et ts=4 :
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