Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 31e5939

Browse files
committed
Escape className
1 parent 0136138 commit 31e5939

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.1] - 2019-12-20
9+
10+
### Fixed
11+
- The `className` option is now properly escaped in the generated CSS
12+
813
## [1.0.0] - 2019-12-20
914

1015
Initial release
1116

12-
[Unreleased]: https://github.com/benface/tailwindcss-alt/compare/v1.0.0...HEAD
17+
[Unreleased]: https://github.com/benface/tailwindcss-alt/compare/v1.0.1...HEAD
18+
[1.0.1]: https://github.com/benface/tailwindcss-alt/releases/tag/v1.0.1
1319
[1.0.0]: https://github.com/benface/tailwindcss-alt/releases/tag/v1.0.0

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const _ = require('lodash');
22
const selectorParser = require('postcss-selector-parser');
33

44
module.exports = function(options = {}) {
5-
return ({ addVariant }) => {
5+
return ({ addVariant, e }) => {
66
const defaultOptions = {
77
className: 'alt',
88
};
@@ -14,7 +14,7 @@ module.exports = function(options = {}) {
1414
return selectorParser(selectors => {
1515
selectors.walkClasses(classNode => {
1616
classNode.value = `${options.className}${separator}${pseudoClass}${separator}${classNode.value}`;
17-
classNode.parent.insertBefore(classNode, selectorParser().astSync(`.${options.className} `));
17+
classNode.parent.insertBefore(classNode, selectorParser().astSync(`.${e(options.className)} `));
1818
classNode.parent.insertAfter(classNode, selectorParser.pseudo({ value: `:${pseudoClass}` }));
1919
});
2020
}).processSync(selector);
@@ -28,7 +28,7 @@ module.exports = function(options = {}) {
2828
return selectorParser(selectors => {
2929
selectors.walkClasses(classNode => {
3030
classNode.value = `${options.className}${separator}group-${pseudoClass}${separator}${classNode.value}`;
31-
classNode.parent.insertBefore(classNode, selectorParser().astSync(`.${options.className} .group:${pseudoClass} `));
31+
classNode.parent.insertBefore(classNode, selectorParser().astSync(`.${e(options.className)} .group:${pseudoClass} `));
3232
});
3333
}).processSync(selector);
3434
});
@@ -40,7 +40,7 @@ module.exports = function(options = {}) {
4040
return selectorParser(selectors => {
4141
selectors.walkClasses(classNode => {
4242
classNode.value = `${options.className}${separator}${classNode.value}`;
43-
classNode.parent.insertBefore(classNode, selectorParser().astSync(`.${options.className} `));
43+
classNode.parent.insertBefore(classNode, selectorParser().astSync(`.${e(options.className)} `));
4444
});
4545
}).processSync(selector);
4646
});

test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,18 @@ test('the alt class name can be customized', () => {
248248
`);
249249
});
250250
});
251+
252+
test('custom class names are escaped', () => {
253+
return generatePluginCss(['alt'], {
254+
className: 'test-1/2',
255+
}).then(css => {
256+
expect(css).toMatchCss(`
257+
.block {
258+
display: block;
259+
}
260+
.test-1\\/2 .test-1\\/2\\:block {
261+
display: block;
262+
}
263+
`);
264+
});
265+
});

0 commit comments

Comments
 (0)