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
70daee86
Commit
70daee86
authored
10 years ago
by
LarsDW223
Browse files
Options
Downloads
Patches
Plain Diff
Corrected compression for ++ and -- operator. Partially fixes #897.
parent
b2e6a1f4
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/js_js_compress.test.php
+60
-0
60 additions, 0 deletions
_test/tests/lib/exe/js_js_compress.test.php
lib/exe/js.php
+23
-11
23 additions, 11 deletions
lib/exe/js.php
with
83 additions
and
11 deletions
_test/tests/lib/exe/js_js_compress.test.php
+
60
−
0
View file @
70daee86
...
...
@@ -145,6 +145,66 @@ EOF;
$this
->
assertEquals
(
$out
,
js_compress
(
$text
));
}
function
test_plusplus1
(){
$text
=
'a = 5 + ++b;'
;
$this
->
assertEquals
(
'a=5+ ++b;'
,
js_compress
(
$text
));
}
function
test_plusplus2
(){
$text
=
'a = 5+ ++b;'
;
$this
->
assertEquals
(
'a=5+ ++b;'
,
js_compress
(
$text
));
}
function
test_plusplus3
(){
$text
=
'a = 5++ + b;'
;
$this
->
assertEquals
(
'a=5++ +b;'
,
js_compress
(
$text
));
}
function
test_plusplus4
(){
$text
=
'a = 5++ +b;'
;
$this
->
assertEquals
(
'a=5++ +b;'
,
js_compress
(
$text
));
}
function
test_minusminus1
(){
$text
=
'a = 5 - --b;'
;
$this
->
assertEquals
(
'a=5- --b;'
,
js_compress
(
$text
));
}
function
test_minusminus2
(){
$text
=
'a = 5- --b;'
;
$this
->
assertEquals
(
'a=5- --b;'
,
js_compress
(
$text
));
}
function
test_minusminus3
(){
$text
=
'a = 5-- - b;'
;
$this
->
assertEquals
(
'a=5-- -b;'
,
js_compress
(
$text
));
}
function
test_minusminus4
(){
$text
=
'a = 5-- -b;'
;
$this
->
assertEquals
(
'a=5-- -b;'
,
js_compress
(
$text
));
}
function
test_minusplus1
(){
$text
=
'a = 5-- +b;'
;
$this
->
assertEquals
(
'a=5--+b;'
,
js_compress
(
$text
));
}
function
test_minusplus2
(){
$text
=
'a = 5-- + b;'
;
$this
->
assertEquals
(
'a=5--+b;'
,
js_compress
(
$text
));
}
function
test_plusminus1
(){
$text
=
'a = 5++ - b;'
;
$this
->
assertEquals
(
'a=5++-b;'
,
js_compress
(
$text
));
}
function
test_plusminus2
(){
$text
=
'a = 5++ -b;'
;
$this
->
assertEquals
(
'a=5++-b;'
,
js_compress
(
$text
));
}
/**
* Test the files provided with the original JsStrip
*/
...
...
This diff is collapsed.
Click to expand it.
lib/exe/js.php
+
23
−
11
View file @
70daee86
...
...
@@ -289,6 +289,10 @@ function js_compress($s){
// items that don't need spaces next to them
$chars
=
"^&|!+\-*\/%=\?:;,{}()<>%
\t\n\r
'
\"
[]"
;
// items which need a space if the sign before and after whitespace is equal.
// E.g. '+ ++' may not be compressed to '+++' --> syntax error.
$ops
=
"+-"
;
$regex_starters
=
array
(
"("
,
"="
,
"["
,
","
,
":"
,
"!"
);
$whitespaces_chars
=
array
(
" "
,
"
\t
"
,
"
\n
"
,
"
\r
"
,
"
\0
"
,
"
\x0B
"
);
...
...
@@ -389,19 +393,27 @@ function js_compress($s){
// whitespaces
if
(
$ch
==
' '
||
$ch
==
"
\r
"
||
$ch
==
"
\n
"
||
$ch
==
"
\t
"
){
// leading spaces
if
(
$i
+
1
<
$slen
&&
(
strpos
(
$chars
,
$s
[
$i
+
1
])
!==
false
)){
$i
=
$i
+
1
;
continue
;
}
// trailing spaces
// if this ch is space AND the last char processed
// is special, then skip the space
$lch
=
substr
(
$result
,
-
1
);
if
(
$lch
&&
(
strpos
(
$chars
,
$lch
)
!==
false
)){
$i
=
$i
+
1
;
continue
;
// Only consider deleting whitespace if the signs before and after
// are not equal and are not an operator which may not follow itself.
if
((
!
$lch
||
$s
[
$i
+
1
]
==
' '
)
||
$lch
!=
$s
[
$i
+
1
]
||
strpos
(
$ops
,
$s
[
$i
+
1
])
===
false
)
{
// leading spaces
if
(
$i
+
1
<
$slen
&&
(
strpos
(
$chars
,
$s
[
$i
+
1
])
!==
false
)){
$i
=
$i
+
1
;
continue
;
}
// trailing spaces
// if this ch is space AND the last char processed
// is special, then skip the space
if
(
$lch
&&
(
strpos
(
$chars
,
$lch
)
!==
false
)){
$i
=
$i
+
1
;
continue
;
}
}
// else after all of this convert the "whitespace" to
// a single space. It will get appended below
$ch
=
' '
;
...
...
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