Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix leading whitespace issue.

Any leading whitespace in the style should be ignored, however care must
be taken to handle comments if they exist.

The problem is exposed once the test comparison function does not strip
the leading and trailing whitespaces.
  • Loading branch information...
commit c6d837ca1927d7e0b157f22c50592207096c2cee 1 parent 6758296
Ariya Hidayat authored
Showing with 14 additions and 5 deletions.
  1. +12 −2 cssbeautify.js
  2. +2 −3 test.htm
View
14 cssbeautify.js
@@ -165,6 +165,12 @@ function cssbeautify(style, opt) {
if (state === State.Start) {
+ if (blocks.length === 0) {
+ if (isWhitespace(ch) && formatted.length === 0) {
+ continue;
+ }
+ }
+
// Copy white spaces and control characters
if (ch <= ' ' || ch.charCodeAt(0) >= 128) {
state = State.Start;
@@ -182,7 +188,9 @@ function cssbeautify(style, opt) {
// If we have empty string after removing all the trailing
// spaces, that means we are right after a block.
// Ensure a blank line as the separator.
- formatted = '\n\n';
+ if (blocks.length > 0) {
+ formatted = '\n\n';
+ }
} else {
// After finishing a ruleset or directive statement,
// there should be one blank line.
@@ -240,7 +248,9 @@ function cssbeautify(style, opt) {
// If we have empty string after removing all the trailing
// spaces, that means we are right after a block.
// Ensure a blank line as the separator.
- formatted = '\n\n';
+ if (blocks.length > 0) {
+ formatted = '\n\n';
+ }
} else {
// Insert blank line if necessary.
if (str.charAt(str.length - 1) === '}') {
View
5 test.htm
@@ -333,7 +333,6 @@
h1 {
color: red;
}
-
</pre>
<h2>Animation keyframes</h2>
@@ -379,7 +378,7 @@
}
if (cls === 'ref') {
data[id] = data[id] || {};
- data[id].ref = e.innerHTML.replace(/^\s+/, '').replace(/\s+$/, '');
+ data[id].ref = e.innerHTML;
}
if (cls === 'status') {
data[id] = data[id] || {};
@@ -393,7 +392,7 @@
if (data.hasOwnProperty(name)) {
total += 1;
test = data[name];
- test.result = cssbeautify(test.source).replace(/^\s+/, '').replace(/\s+$/, '');
+ test.result = cssbeautify(test.source);
if (test.result !== test.ref) {
failures += 1;
e = document.createElement('pre');
Please sign in to comment.
Something went wrong with that request. Please try again.