This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit f9af40f625bf2ce6b76e997cf9a6fbd764b3f980 Author: Josh Tynjala <[email protected]> AuthorDate: Tue Oct 7 14:56:38 2025 -0700 CSS: make parsing of attribute selectors stricter An operator and a value are optional, but if one exists, both must exist. --- .../org/apache/royale/compiler/internal/css/CSS.g | 2 +- .../apache/royale/compiler/internal/css/CSSTree.g | 31 ++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g index c21f282a3..64f295df8 100644 --- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g +++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g @@ -520,7 +520,7 @@ formatOption ; attributeSelector - : SQUARE_OPEN attributeName attributeOperator* attributeValue* SQUARE_END + : SQUARE_OPEN attributeName (attributeOperator attributeValue)? SQUARE_END ; attributeName diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g index 0322d3025..070096355 100644 --- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g +++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g @@ -386,9 +386,16 @@ elementSelector | STAR { $simpleSelector::element = $STAR.text; } ; - + +/** + * Matches an attribute selector. + * + * Must starts with an opening square bracket and end with a closing square + * bracket. Inside the brackets, it must start with attribute name. An operator + * and value may optionally follow, but if either exists, both must exist. + */ attributeSelector - : open = SQUARE_OPEN attributeName attributeOperator* attributeValue* close = SQUARE_END + : open = SQUARE_OPEN attributeName (attributeOperator attributeValue)? close = SQUARE_END { if (strictFlexCSS) { @@ -398,12 +405,20 @@ attributeSelector curAttribute = $open.text + curAttribute + $close.text; } ; - + +/** + * Matches an attribute name within an attribute selector. + */ attributeName : n1 = ID { curAttribute = $n1.text; } ; - + +/** + * Matches an operator within an attribute selector. + * + * Immediately follows the attribute name. + */ attributeOperator : o1 = BEGINS_WITH { curAttribute += $o1.text; } @@ -418,7 +433,13 @@ attributeOperator | o6 = EQUALS { curAttribute += $o6.text; } ; - + + +/** + * Matches a value within an attribute selector. + * + * Immediately follows the attribute operator. + */ attributeValue : s = STRING { curAttribute += $s.text; }
