Skip to content

Commit 39b8e36

Browse files
committed
sanitize selectors
1 parent 127f732 commit 39b8e36

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/utils/strings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ export function toCamelCase(value: string | undefined): string {
1212
export function isNumber(value: string): boolean {
1313
return value.match(numberRegex) !== null;
1414
}
15+
16+
export function sanitizeSelector(value: string): string {
17+
return value.replace(/([\n\r\t ]+)/ig, ' ');
18+
}

src/walkers/RuleWalker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as postcss from 'postcss';
22
import { DeclarationWalker } from './DeclarationWalker';
33
import { Properties } from '../types';
4+
import { sanitizeSelector } from '../utils/strings';
45

56

67
export class RuleWalker {
@@ -23,6 +24,6 @@ export class RuleWalker {
2324
});
2425

2526
// convert to string and add to file
26-
this._rules[rule.selector] = decWalker.getProperties();
27+
this._rules[sanitizeSelector(rule.selector)] = decWalker.getProperties();
2728
}
2829
}

tests/basic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@ cssRule('@page', {
110110

111111
expect(convertCss(testCase)).to.eventually.equal(result).notify(done);
112112
});
113+
113114
});

tests/strings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as assert from 'assert';
2+
import { sanitizeSelector } from '../src/utils/strings';
3+
4+
describe('strings', () => {
5+
it('sanitizeSelector()', () => {
6+
assert.equal(sanitizeSelector(`.first \n\t \r.second`), '.first .second');
7+
});
8+
});

0 commit comments

Comments
 (0)