Skip to content

Line breaks in selectors generate wrong rule #406

Closed

Description

@default007

This valid CSS works well with LESS:

.tabs a {color:#454545;}

is converted into

.tabs a {
color: #454545;
}

But it the selector contains a line break LESS converts it into a wrong rule:

.tabs
a {color:#454545;}

is converted into

.tabsa {
color: #454545;
}

which, of course, breaks my layout completely :-)

Activity

  1. revolunet commented on Sep 29, 2011

    @revolunet
    Contributor

    i think i fixed this issue here : revolunet@eaa6f26

    not merged in main repo though

  2. ChrisCinelli commented on Oct 3, 2011

    @ChrisCinelli

    @revolunet. IT sound right. Issue a pull request and hopefully Cloudhead will add it.

  3. revolunet commented on Oct 3, 2011

    @revolunet
    Contributor

    did you test this modif ?

  4. ChrisCinelli commented on Oct 3, 2011

    @ChrisCinelli

    No. I thought you did. Definitely need to be done.
    I looked at the parser code. It seems that it does not have a tokenier and everything is character based instead of token based. It should be rewritten completely but it seemed that your patch may work for the moment.

  5. added a commit that references this issue on Oct 3, 2011
  6. revolunet commented on Oct 3, 2011

    @revolunet
    Contributor

    please confirm this last commit works for you

  7. default007 commented on Oct 4, 2011

    @default007
    Author

    Please notice that a similar bug also happens with line breaks inside the rule description. The following valid output of a minifier:

    .push{margin:5px
    -160px 1.5em 160px}

    is converted into

    .push {
    margin: -155px 1.5em 160px;
    }

    The maths are computed between the first two items, and I get a subtraction!

  8. ChrisCinelli commented on Oct 4, 2011

    @ChrisCinelli

    @default007: This is a different thing.

    File a new bug.

    It's actually the intended behavior but I agree with you that is not what should happen. It would be better if a math expression has to be inside @(...) or something in order to avoid these kind of problems. Right now the way to go around this is using escaping ~"..."
    In your example:
    .push{margin: ~"5px -160px 1.5em 160px"}

    I think it would be better to specify (because less common) when an arithmetic operation is expected instead of having to specify when it is not expected.

  9. default007 commented on Oct 5, 2011

    @default007
    Author

    File a new bug.

    Is it? It only happens after a line break. The following, for example, works OK:

    .push{margin: 5px -160px 1.5em 160px}

    That I don't need to escape.

    It also works if I apply a hack to my minifier, to put a space after the line break, like this:

    .push{margin:5px
     -160px 1.5em 160px}
    
  10. ChrisCinelli commented on Oct 10, 2011

    @ChrisCinelli

    CSS is a free-form language (http://en.wikipedia.org/wiki/Free-form_language) in which the positioning of characters on the page in program text is not significant. Which characters are used \n \t etc and their number should do not matter.

    This is not currently true for less.js and it makes not fully compatible with CSS syntax. In my humble opinion this should be changed.

    As I wrote in a comment above, less.js' parser does not have a tokenizer. There are a lot of comparisons with a normal space (' ') in the code that create peculiar behaviors like the one you described. Something like this should be used: http://www.cdiggins.com/tokenizer.html

    In the past when I had to implement one, I used interfaces similar to Tokenizer.getCurrentToken(), Tokenizer.followingToken(), Tokenizer.previousToken(), Tokenizer.next()

  11. added a commit that references this issue on Aug 19, 2012
  12. lukeapage commented on Aug 19, 2012

    @lukeapage
    Member

    @ChrisCinelli it doesn't have a "proper" tokenizer.. anyway, have pulled fix from @revolunet.

    There is one more place looking at space and that causes the bug mentioned above.. will look at it next.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions