Page MenuHomePhabricator

Treat single and double quotes as equal in "when" operator
Closed, ResolvedPublic

Description

Reported by @driskell@github.com at https://github.com/wikimedia/less.php/issues/77 (26 April 2022):

Single and double quote are treated as different identifiers. This is contrast to javascript based LESS that treats a quoted identifier as a quoted identifier regardless of whether the quotes were single or double. It can cause a little confusion.

As an example:

.test-mixin(@value) when (@value = "test") {
  background: red;
}

.test-mixin(@value) when (@value = 'test') {
  background: blue;
}

double {
  .test-mixin("test")
}
single {
  .test-mixin('test')
}

Using wikimedia/less.php this compiles to the following:

double {
  background: red;
}
single {
  background: blue;
}

However, using lessc Node module you get:

double {
  background: red;
  background: blue;
}
single {
  background: red;
  background: blue;
}

Using versions:

$ lessc --version
lessc 4.1.2 (Less Compiler) [JavaScript]
$ ./vendor/bin/lessc --version
lessc 3.1.0 (less.php)

Event Timeline

I've confirmed out behaviour to match upstream Less.js 1.7.0, and this was changed in Less.js 1.7.1.

http://ecomfe.github.io/est/fiddle/#version=1.7.0&autoprefix=false&est=false&autorun=false

Our tests didn't catch this because the relevant test case (upstream test/less/mixins-guards.less) is disabled in our repo pending a fix for a different known issue (T352867).

Based on the changelog at https://github.com/less/less.js/commits/v1.7.1/, porting https://github.com/less/less.js/commit/5647d4d27614a1d18e331eecb20fe53032ca994e should fix this.

Change 999959 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/libs/less.php@master] Less_Tree_Quoted: Ignore quote type when comparing values

https://gerrit.wikimedia.org/r/999959

Krinkle triaged this task as Medium priority.Feb 9 2024, 5:46 PM

Change 999959 merged by jenkins-bot:

[mediawiki/libs/less.php@master] Less_Tree_Quoted: Ignore quote type when comparing values

https://gerrit.wikimedia.org/r/999959