Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/parser/cssParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,8 @@ export class Parser {
}

public _parseHexColor(): nodes.Node | null {
if (this.peekRegExp(TokenType.Hash, /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/g)) {
// accept any length, the lint rule hexColorLength reports the invalid ones
if (this.peekRegExp(TokenType.Hash, /^#[A-Fa-f0-9]+$/g)) {
const node = this.create(nodes.HexColorValue);
this.consumeToken();
return this.finish(node);
Expand Down
9 changes: 9 additions & 0 deletions src/test/css/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ suite('CSS - Lint', () => {
assertRuleSet('#selector { display: inline; }', Rules.AvoidIdSelector);
});

test('hex color length', function () {
assertRuleSet('selector { color: #fff; background: #ffff; border-color: #ffffff; outline-color: #ffffffff }');
assertRuleSet('selector { color: #f }', Rules.HexColorLength);
assertRuleSet('selector { color: #ff }', Rules.HexColorLength);
assertRuleSet('selector { color: #fffff }', Rules.HexColorLength);
assertRuleSet('selector { color: #fffffff }', Rules.HexColorLength);
assertRuleSet('selector { border: 1px solid #fffffffff }', Rules.HexColorLength);
});

test('zero with unit', function () {
assertRuleSet('selector { width: 0px }', Rules.ZeroWithUnit);
assertRuleSet('selector { width: 0Px }', Rules.ZeroWithUnit);
Expand Down
7 changes: 7 additions & 0 deletions src/test/css/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,13 @@ suite('CSS - Parser', () => {
assertNode('#FFFF', parser, parser._parseHexColor.bind(parser));
assertNode('#FFFFFF', parser, parser._parseHexColor.bind(parser));
assertNode('#FFFFFFFF', parser, parser._parseHexColor.bind(parser));
// invalid lengths are still hex colors, the lint rule hexColorLength reports them
assertNode('#F', parser, parser._parseHexColor.bind(parser));
assertNode('#FF', parser, parser._parseHexColor.bind(parser));
assertNode('#FFFFF', parser, parser._parseHexColor.bind(parser));
assertNode('#FFFFFFFFF', parser, parser._parseHexColor.bind(parser));
assertNoNode('#FFG', parser, parser._parseHexColor.bind(parser));
assertNode('a { color: #12; }', parser, parser._parseStylesheet.bind(parser));
});

test('test class', function () {
Expand Down