]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Project] Css: More meat to the lexer
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 Jan 2021 15:48:40 +0000 (15:48 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 Jan 2021 15:48:40 +0000 (15:48 +0000)
src/libserver/css/css_tokeniser.cxx
src/libserver/css/css_tokeniser.hxx

index f545af47a765ddf97b5172544556a2398931cd3b..49032c64f8cec6594465d03eefdd243e52a3218a 100644 (file)
@@ -546,11 +546,83 @@ auto css_tokeniser::next_token(void) -> struct css_parser_token
                                        /* Numeric token */
                                        return consume_number();
                                }
+                               else {
+                                       offset = i + 1;
+                                       return make_token<css_parser_token::token_type::delim_token>(c);
+                               }
                        }
                        /* No other options, a delimiter - */
                        offset = i + 1;
                        return make_token<css_parser_token::token_type::delim_token>(c);
 
+                       break;
+               case '\\':
+                       if (i + 1 < input.size()) {
+                               if (input[i + 1] == '\n' || input[i + 1] == '\r') {
+                                       offset = i + 1;
+                                       return make_token<css_parser_token::token_type::delim_token>(c);
+                               }
+                               else {
+                                       /* Valid escape, assume ident */
+                                       return consume_ident();
+                               }
+                       }
+                       else {
+                               offset = i + 1;
+                               return make_token<css_parser_token::token_type::delim_token>(c);
+                       }
+                       break;
+               case '@':
+                       if (i + 3 < input.size()) {
+                               if (is_plain_ident(input[i + 1]) &&
+                                       is_plain_ident(input[i + 2]) && is_plain_ident(input[i + 3])) {
+                                       offset = i + 1;
+                                       auto ident_token = consume_ident();
+
+                                       if (ident_token.type == css_parser_token::token_type::ident_token) {
+                                               /* Update type */
+                                               ident_token.type = css_parser_token::token_type::at_keyword_token;
+                                       }
+
+                                       return ident_token;
+                               }
+                               else {
+                                       offset = i + 1;
+                                       return make_token<css_parser_token::token_type::delim_token>(c);
+                               }
+                       }
+                       else {
+                               offset = i + 1;
+                               return make_token<css_parser_token::token_type::delim_token>(c);
+                       }
+                       break;
+               case '#':
+                       /* TODO: make it more conformant */
+                       if (i + 2 < input.size()) {
+                               if (is_plain_ident(input[i + 1]) &&
+                                       is_plain_ident(input[i + 2])) {
+                                       offset = i + 1;
+                                       auto ident_token = consume_ident();
+
+                                       if (ident_token.type == css_parser_token::token_type::ident_token) {
+                                               /* Update type */
+                                               ident_token.type = css_parser_token::token_type::hash_token;
+                                       }
+
+                                       return ident_token;
+                               }
+                               else {
+                                       offset = i + 1;
+                                       return make_token<css_parser_token::token_type::delim_token>(c);
+                               }
+                       }
+                       else {
+                               offset = i + 1;
+                               return make_token<css_parser_token::token_type::delim_token>(c);
+                       }
+                       break;
+               default:
+                       /* Generic parsing code */
                        break;
                }
 
index 5880241c12f28d1371a11fb97c5b217d5f000497..cd9c47cfd402aa77b3307e284961be06c650144b 100644 (file)
@@ -38,8 +38,6 @@ struct css_parser_token {
                string_token,
                number_token,
                url_token,
-               dimension_token,
-               percentage_token,
                cdo_token, /* xml open comment */
                cdc_token, /* xml close comment */
                delim_token,