Procházet zdrojové kódy

LibWeb: Reject invalid tokens in `calc()` expressions

If we finish parsing a calculation tree and it still contains
UnparsedCalculationNodes, then it's not valid, and we shouldn't create
a StyleValue from it.
Sam Atkins před 2 roky
rodič
revize
4e47e6a3d6
1 změnil soubory, kde provedl 6 přidání a 0 odebrání
  1. 6 0
      Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

+ 6 - 0
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -7591,6 +7591,7 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal
                 return {};
             }
             node = leaf_calculation.release_nonnull();
+            return {};
         }
 
         // 2. If leaf is a math function, replace leaf with the internal representation of that math function.
@@ -7604,6 +7605,7 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal
                     return {};
                 }
                 node = leaf_calculation.release_nonnull();
+                return {};
             } else {
                 // FIXME: Parse more math functions once we have them.
                 parsing_failed_for_child_node = true;
@@ -7611,6 +7613,10 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal
             }
         }
 
+        // NOTE: If we get here, then we have an UnparsedCalculationNode that didn't get replaced with something else.
+        //       So, the calc() is invalid.
+        dbgln_if(CSS_PARSER_DEBUG, "Leftover UnparsedCalculationNode in calc tree! That probably means the syntax is invalid, but maybe we just didn't implement `{}` yet.", component_value.to_debug_string());
+        parsing_failed_for_child_node = true;
         return {};
     }));