postcss-selector-parser: Unexpected attribute parse behaviour in 3.0.0-rc.0

One of our users reported an issue with the new alpha of cssnano. Upon examining the issue more closely I discovered that it fails on the following selector from the angular-material package:

[ng\:cloak]

This seems to have to do with a change to postcss-selector-parser affecting how attributes are parsed. Compare the following:

3.0.0-rc.0:

Attribute {
  ...
  attribute: 'ng',
  value: '\\:',
  raws: { unquoted: '\\:' },
  spaces: { before: '', after: '' },
  ...
}

v2.2.3:

Attribute {
  ...
  operator: undefined,
  value: undefined,
  attribute: 'ng\\:cloak',
  spaces: { before: '', after: '' },
  raws: {},
  ...
}

While the changelog does mention the possibility of breaking changes, I think this is likely a bug.

\cc @ben-eb

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 31 (24 by maintainers)

Most upvoted comments

Ok, this change is still a work in progress to have a consistent behavior across the library, but I’ve got the basic strategy implemented for attributes.

https://github.com/postcss/postcss-selector-parser/compare/escape-handling

Among other things, there’s deprecation warnings caused by internal API use, but I’d like to get some feedback on whether this change looks directionally correct before I carry it through the library and tidy up the internals.

@evilebottnawi this change will require updates to consuming libraries to avoid deprecation warnings. feedback on the new API is helpful.

@ai I didn’t find the escape handling code in postcss so I wrote my own unescape function - it wasn’t too hard. I’m using the cssesc library to handle escaping values for string and identifiers.

@andyjansson if you have a chance to review, I’d appreciate it!

I can fix this in the selector parser. After thinking about it, I don’t think it’s fixable in core without making this module part of the core and in that case I still have to fix it.

I have a few other patches to get out. I’ll take a swing at this today.

@chriseppstein i just remove invalid tests 👍

@evilebottnawi contributors is not a problem. I can use the power of out Cult of Martians. But in this case, we will put escaping to the parser. Putting it to the core is dangerous and requires more time to think.

I will make Cult of Martians task this Friday.

It can’t be solved in the core in next month (moving to US, crazy time). Solve it temporary in this parser.