Skip to content

Commit 317e275

Browse files
authored
fix: throw on unexpected pipe symbols (postcss#278)
1 parent 2c24f44 commit 317e275

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/__tests__/namespaces.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {test} from './util/helpers.mjs';
1+
import {test, throws} from './util/helpers.mjs';
22

33
test('match tags in the postcss namespace', 'postcss|button', (t, tree) => {
44
t.deepEqual(tree.nodes[0].nodes[0].namespace, 'postcss');
@@ -76,3 +76,10 @@ test('ns alias for namespace', 'f\\oo|h1.foo', (t, tree) => {
7676
t.deepEqual(tag.namespace, 'bar');
7777
t.deepEqual(tag.ns, 'bar');
7878
});
79+
80+
throws('lone pipe symbol', '|');
81+
throws('lone pipe symbol with leading spaces', ' |');
82+
throws('lone pipe symbol with trailing spaces', '| ');
83+
throws('lone pipe symbol with surrounding spaces', ' | ');
84+
throws('trailing pipe symbol with a namespace', 'foo| ');
85+
throws('trailing pipe symbol with any namespace', '*| ');

src/parser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,10 @@ export default class Parser {
646646
return this.error(`Unexpected '${this.content()}'. Escaping special characters with \\ may help.`, this.currToken[TOKEN.START_POS]);
647647
}
648648

649+
unexpectedPipe () {
650+
return this.error(`Unexpected '|'.`, this.currToken[TOKEN.START_POS]);
651+
}
652+
649653
namespace () {
650654
const before = this.prevToken && this.content(this.prevToken) || true;
651655
if (this.nextToken[TOKEN.TYPE] === tokens.word) {
@@ -655,6 +659,8 @@ export default class Parser {
655659
this.position ++;
656660
return this.universal(before);
657661
}
662+
663+
this.unexpectedPipe();
658664
}
659665

660666
nesting () {

0 commit comments

Comments
 (0)