Skip to content

Misparsed attribute selector #366

Open

Description

@fisker

It seems we allow and ignore everything between the operator and the quotes of value.

> require('postcss-selector-parser')(x => console.log(x.nodes[0].nodes[0])).processSync("[class=XXX'@{foo}-']")
<ref *1> Attribute {
  source: { start: { line: 1, column: 1 }, end: { line: 1, column: 20 } },
  sourceIndex: 0,
  _attribute: 'class',
  operator: '=',
  _value: '@{foo}-',
  _quoteMark: "'",
  raws: { value: "'@{foo}-'" },
  spaces: { before: '', after: '' },
  type: 'attribute',
  _constructed: true,
  parent: Selector {
    source: { start: [Object], end: [Object] },
    sourceIndex: 0,
    spaces: { before: '', after: '' },
    nodes: [ [Circular *1] ],
    type: 'selector',
    parent: Root {
      source: [Object],
      spaces: [Object],
      nodes: [Array],
      type: 'root',
      _error: [Function (anonymous)]
    }
  }
}

There is no information about XXX between = and '.

Found this when trying to support a valid selector in LESS [class=~'@{foo}-']

@foo: x;

[class=~'@{foo}-'] {
color: red;
  
}

LESS playground

This syntax seems not allowed in LESS 5, so I'm fine to reject it when parsing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions