Skip to content

each() handles strings differently when length of list is 1  #3354

@gweax

Description

@gweax

Short version: When a list of length 1 is passed and the list contains a string with quotes, the quotes are removed.

Long version: Consider this code:

.log(@msgs) {
  each(@msgs; {
    content: @value;
  }
}

@messages: 'foo', 'bar';

span {
  .log(@messages);
}

div {
  .log('foo');
}

The output is this:

span {
  content: 'foo';
  content: 'bar';
}

div {
  content: foo;
}

In the first example the quotes around the list items are preserved. In the second example, the quotes are removed.

I could get a consistent result by using the e() function to always remove the quotes, but in some cases I might want to keep them.

I created an estfiddle for the above code: http://ecomfe.github.io/est/fiddle/#code=LmxvZyhAbXNncykgewogICAgZWFjaChAbXNnczsgewogICAgICAgIGNvbnRlbnQ6IEB2YWx1ZTsKICAgIH0pOwp9CgpAbWVzc2FnZXM6ICdmb28nLCAnYmFyJzsKCnNwYW4gewogICAgLmxvZyhAbWVzc2FnZXMpOwp9CgpkaXYgewogICAgLmxvZygnZm9vJyk7Cn0K

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions