Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix multiline comment start #80

Merged
merged 2 commits into from

1 participant

@JohnAlbin
Owner

Over in #24, @mscheibe noted that:

Compass Sprite imports can be of the form @import "folder/*.png". This matches the regex for multi-line comments and the rest of the file would then be ignored.

Looking at this more closely, I see that other, similar strings can cause the same failure:

  • .rule { content: "/*"; }
  • /* A multi-line comment on a single line */

Properly parsing CSS strings and comments is a difficult task. Fortunately, the KSS spec implies that we only should care about clean multi-line comments that start and end on their own lines. This is much easier to match with regex.

@JohnAlbin JohnAlbin merged commit 2f8f170 into from
@JohnAlbin JohnAlbin added this to the 1.0.0 milestone
@JohnAlbin JohnAlbin deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 lib/kss.js
@@ -13,10 +13,9 @@ var walk = require('./walk.js'),
traverse, parse, parseChunk, checkReference, findBlocks, processMarkup,
isDeprecated, isExperimental, hasPrefix,
commentExpressions = {
- single: /\s*?\/\/(.*?)$/g,
- multiStart: /\/\*\!?(.*?)$/,
- multiFinish: /\*\//,
- multiBeforeFinish: /(.*?)\*\//
+ single: /^\s*\/\/.*$/g,
+ multiStart: /^\s*\/\*+\s*$/,
+ multiFinish: /^\s*\*\/\s*$/
};
/**
View
47 test/fixtures-styles/options-comment-syntax.less
@@ -0,0 +1,47 @@
+/*
+Comment syntax: multi-line
+
+Using multi-line comment syntax.
+
+Markup:
+<a href="#" class="{$modifiers}">Hello World</a>
+
+:hover - Highlights when moused over
+:disabled - Dims when unavailable
+.primary - Indicates this is a key element
+
+Styleguide 1.1
+*/
+
+// Comment syntax: inline
+//
+// Using inline comment syntax.
+//
+// Styleguide 1.2
+
+
+.example-1-3 {
+ content: 'This string includes the start of a multi-line comment: /*';
+}
+
+// False-positive of multi-line comment block #1
+//
+// Styleguide 1.3
+
+// This single-line comment includes the end of a multi-line comment: */
+
+
+/* A multi-line comment on a single line. */
+
+// False-positive of multi-line comment block #2
+//
+// Markup:
+// <a href="#" class="{$modifiers}">Hello World</a>
+//
+// :hover - Highlights when moused over
+// :disabled - Dims when unavailable
+// .primary - Indicates this is a key element
+//
+// Styleguide 1.4
+
+// This single-line comment includes the end of a multi-line comment: */
View
17 test/kss.js
@@ -306,6 +306,23 @@ suite('#traverse', function() {
});
});
suite('options', function() {
+ suite('.comment-syntax', function() {
+ common.testSection('Comment syntax: multi-line', 'options-comment-syntax.less', function(section) {
+ assert.equal(section.data.reference, '1.1');
+ }, false, { markup: true });
+
+ common.testSection('Comment syntax: inline', 'options-comment-syntax.less', function(section) {
+ assert.equal(section.data.reference, '1.2');
+ }, false, { markup: true });
+
+ common.testSection('False-positive of multi-line comment block #1', 'options-comment-syntax.less', function(section) {
+ assert.equal(section.data.reference, '1.3');
+ }, false, { markup: true });
+
+ common.testSection('False-positive of multi-line comment block #2', 'options-comment-syntax.less', function(section) {
+ assert.equal(section.data.reference, '1.4');
+ }, false, { markup: true });
+ }),
suite('.markup', function() {
common.testSection('Second paragraph', 'options-markup.less', function(section) {
assert.equal(
Something went wrong with that request. Please try again.