Visitar URL original
Fix Rule#selectors losing the empty selector (#2129) · postcss/postcss@1493a83 · GitHub
Skip to content

Commit 1493a83

Browse files
authored
Fix Rule#selectors losing the empty selector (#2129)
1 parent 180db16 commit 1493a83

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎lib/list.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let list = {
1111
},
1212

1313
split(string, separators, last) {
14-
if (!string) return []
14+
if (typeof string !== 'string') return []
1515
let array = []
1616
let current = ''
1717
let split = false

‎test/list.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ test('comma() adds last empty', () => {
3636
equal(list.comma('a, b,'), ['a', 'b', ''])
3737
})
3838

39+
test('comma() keeps empty value', () => {
40+
equal(list.comma(''), [''])
41+
})
42+
43+
test('comma() ignores non-string values', () => {
44+
// @ts-expect-error Testing invalid API
45+
equal(list.comma(undefined), [])
46+
})
47+
3948
test('comma() checks quotes', () => {
4049
equal(list.comma('"a,b\\"", \'\''), ['"a,b\\""', "''"])
4150
})

‎test/rule.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ test('returns array in selectors', () => {
1313
equal(rule.selectors, ['a', 'b'])
1414
})
1515

16+
test('returns empty selector in selectors', () => {
17+
let rule = new Rule({ selector: '' })
18+
equal(rule.selectors, [''])
19+
})
20+
1621
test('trims selectors', () => {
1722
let rule = new Rule({ selector: '.a\n, .b , .c' })
1823
equal(rule.selectors, ['.a', '.b', '.c'])

0 commit comments

Comments
 (0)