-
-
Notifications
You must be signed in to change notification settings - Fork 187
Add support for identifiers ending with ? in Liquid templates
#841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for identifiers ending with ? in Liquid templates
#841
Conversation
Co-authored-by: sebastienros <[email protected]>
? in Liquid templates
|
@copilot can you add a test that ensures intermediate identifiers in multi segment expression are supported? |
Co-authored-by: sebastienros <[email protected]>
Added tests for intermediate identifiers with trailing
|
Fluid/FluidParserOptions.cs
Outdated
| /// <summary> | ||
| /// Gets whether identifiers can end with a question mark (`?`), which will be stripped during parsing. Default is <c>false</c>. | ||
| /// </summary> | ||
| public bool AllowTrailingQuestion { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot rename to AllowTrailingQuestionMark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to AllowTrailingQuestionMark in commit 7f966c4. Updated all occurrences in FluidParserOptions.cs, FluidParser.cs, and all test files.
Co-authored-by: sebastienros <[email protected]>
Overview
This PR adds support for parsing identifiers that end with a question mark (
?), which are commonly used in Shopify Liquid templates following Ruby naming conventions for predicate methods.Background
Shopify Liquid allows property names and method-like identifiers with a trailing question mark, such as:
product.quantity_price_breaks_configured?collection.products.empty?These identifiers appear in official Shopify themes (like Dawn and Warehouse) and are used extensively in production templates. Currently, Fluid cannot parse these templates, forcing users to pre-process them by removing the trailing question marks.
Implementation
This PR introduces a new parser option
AllowTrailingQuestionMarkthat follows the same pattern as the existingAllowLiquidTagoption:When enabled, the parser:
?during parsing at any position in a multi-segment expression?before creating AST nodes (soempty?becomesempty)?This approach allows seamless integration with existing C# code while maintaining compatibility with Shopify Liquid template syntax.
Key Changes
AllowTrailingQuestionMarkboolean property (defaults tofalse)?charactersIdentifierfield from static to instance to support per-parser configurationExample Usage
Backward Compatibility
The feature is disabled by default, ensuring complete backward compatibility. Existing code continues to work unchanged, and the new behavior is only activated when explicitly enabled via the parser options.
Testing
?on final identifiers?on intermediate identifiers (e.g.,a?.b.c)?(e.g.,a?.b?.c?)Fixes #837
Original prompt
Fixes #837
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.