Menu

Comments handling in CSSParser Vs Browser behavior

Help
Asiya
2017-01-18
2018-04-25
  • Asiya

    Asiya - 2017-01-18

    CSS uses the"block comment" syntax (ie., start a comment with /, and end it with /) and don't support "line comment" //

    Whenever we use // in CSS, the next CSS construct - either declaration or block - will be "commented out" in browser .

    CASE 1 :

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    //comment here
    .foo {
    width: auto;
    height: 500px;
    background: yellow;
    color:red;
    }
    </style>
    </head>
    <body>

    Hello World!


    </body>
    </html>

    Browser behavior - Style with class "foo" will be commented out
    CSS parser behavior - Style with class "foo" will be striped out

    CASE 2 :

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .foo {
    width: auto;
    //comments here
    height: 500px;
    background: yellow;
    color:red;
    }
    </style>
    </head>
    <body>

    Hello World!

    </body>
    </html>

    Browser behavior - In the above Style declarations "height: 500px; background: yellow;color:red;" will be commented out
    CSS parser behavior - In the above Style declarations "height: 500px; background: yellow;color:red;" will be striped out

    CASE 3 :

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .foo {
    width: auto;
    //height: 500px;
    background: yellow;
    color:red;
    }
    </style>
    </head>
    <body>

    Hello World!

    </body>
    </html>

    Browser behavior - In this case, //height: will be consider as invalid css property, hence "background: yellow; color:red;" will be applied in browser

    CSS parser behavior - In the above Style declarations "height: 500px; background: yellow;color:red;" will be striped out

    In CASE3, The browser and parser behavior differs. Is there any way to handle it ?

     
    • RBRi

      RBRi - 2017-01-31

      I'm working on that, but it is not that simple....

      On Wed, 18 Jan 2017 06:29:49 +0000 Asiya wrote:

      CSS uses the"block comment" syntax (ie., start a comment with /, and end it with /) and don't support "line comment" //

      Whenever we use // in CSS, the next CSS construct - either declaration or block - will be "commented out" in browser .

      CASE 1 :

      <!DOCTYPE html>
      <html>
      <head>
      <style>
      //comment here
      ..foo {
      width: auto;
      height: 500px;
      background: yellow;
      color:red;
      }
      </style>
      </head>
      <body>

      Hello World!


      </body>
      </html>

      Browser behavior - Style with class "foo" will be commented out
      CSS parser behavior - Style with class "foo" will be striped out

      CASE 2 :

      <!DOCTYPE html>
      <html>
      <head>
      <style>
      ..foo {
      width: auto;
      //comments here
      height: 500px;
      background: yellow;
      color:red;
      }
      </style>
      </head>
      <body>

      Hello World!


      </body>
      </html>

      Browser behavior - In the above Style declarations "height: 500px; background: yellow;color:red;" will be commented out
      CSS parser behavior - In the above Style declarations "height: 500px; background: yellow;color:red;" will be striped out

      CASE 3 :

      <!DOCTYPE html>
      <html>
      <head>
      <style>
      ..foo {
      width: auto;
      //height: 500px;
      background: yellow;
      color:red;
      }
      </style>
      </head>
      <body>

      Hello World!


      </body>
      </html>

      Browser behavior - In this case, //height: will be consider as invalid css property, hence "background: yellow; color:red;" will be applied in browser

      CSS parser behavior - In the above Style declarations "height: 500px; background: yellow;color:red;" will be striped out

      In CASE3, The browser and parser behavior differs. Is there any way to handle it ?


      Comments handling in CSSParser Vs Browser behavior


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/cssparser/discussion/283564/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       
  • Asiya

    Asiya - 2017-03-10

    is the following changes in SACParserCSS3.java > styleDeclaration() works for above case ?

    final public void styleDeclaration() throws ParseException {
        switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
        case IDENT:
        case ASTERISK:{
          declaration();
          break;
          }
        default:
          jj_la1[89] = jj_gen;
          ;
        }
        label_58:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
          case SEMICOLON:{
            ;
            break;
            }
          default:
            jj_la1[90] = jj_gen;
            break label_58;
          }
          jj_consume_token(SEMICOLON);
          label_59:
          while (true) {
            switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
            case S:{
              ;
              break;
              }
            default:
              jj_la1[91] = jj_gen;
              break label_59;
            }
            jj_consume_token(S);
          }
          switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
          case IDENT:
          case ASTERISK:{
            declaration();
            break;
            }
          **/* FIX : To handle single line comments */           
          case SLASH:{
            error_skipdecl();  
            break;
          }**
          default:
            jj_la1[92] = jj_gen;
            ;
          }
        }
      }
    
     
    • RBRi

      RBRi - 2017-03-26

      Hi Asiya,

      sorry for being not so responsive at the moment.
      The code of this fiel is generated from the javacc parser. I think it is a bad idea to manipulate the generated code. Will be great if you can provide a solution based on changes in the javacc input files.

      RBRi
      

      On Fri, 10 Mar 2017 10:33:54 +0000 Asiya wrote:

      is the following changes in SACParserCSS3.java > styleDeclaration() works for above case ?
      ~~~

      final public void styleDeclaration() throws ParseException {
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case IDENT:
      case ASTERISK:{
      declaration();
      break;
      }
      default:
      jj_la1[89] = jj_gen;
      ;
      }
      label_58:
      while (true) {
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case SEMICOLON:{
      ;
      break;
      }
      default:
      jj_la1[90] = jj_gen;
      break label_58;
      }
      jj_consume_token(SEMICOLON);
      label_59:
      while (true) {
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case S:{
      ;
      break;
      }
      default:
      jj_la1[91] = jj_gen;
      break label_59;
      }
      jj_consume_token(S);
      }
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case IDENT:
      case ASTERISK:{
      declaration();
      break;
      }
      / FIX : To handle single line comments /
      case SLASH:{
      error_skipdecl();
      break;
      }

      default:
      jj_la1[92] = jj_gen;
      ;
      }
      }
      }
      ~~~


      Comments handling in CSSParser Vs Browser behavior


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/cssparser/discussion/283564/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       
      • Asiya

        Asiya - 2017-11-27

        Is this issue resolved ? or Do you require solution in the form of javacc parser generated file ? if so can you share the procedure for generation and share that file ?

         
  • Aniv

    Aniv - 2017-06-07

    Is the above issue fixed, please let us know because it helps me a lot.

    Thanks in advance..

     
  • .Maui

    .Maui - 2018-04-25

    I have updated CSSParser from version 0.9.3 to version 0.9.5.
    The issue hasn't been solved yet.

    There are no news yet?

    Thanks.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.