Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/View/Antlers/Language/Errors/AntlersErrorCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@ class AntlersErrorCodes
const TYPE_UNEXPECTED_EOI_PARSING_SHORTHAND_PARAMETER = 'ANTLR_133';
const TYPE_DIRECTIVE_MISSING_ARGUMENTS = 'ANTLR_134';
const RUNTIME_METHOD_CALL_USER_CONTENT = 'ANTLR_135';
const TYPE_MIXED_MODIFIER_STYLES = 'ANTLR_136';
}
13 changes: 13 additions & 0 deletions src/View/Antlers/Language/Parser/AntlersNodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Statamic\View\Antlers\Language\Nodes\DirectiveNode;
use Statamic\View\Antlers\Language\Nodes\Parameters\ParameterNode;
use Statamic\View\Antlers\Language\Nodes\RecursiveNode;
use Statamic\View\Antlers\Language\Nodes\Structures\ModifierSeparator;
use Statamic\View\Antlers\Language\Nodes\TagIdentifier;
use Statamic\View\Antlers\Language\Runtime\Sandbox\TypeCoercion;
use Statamic\View\Antlers\Language\Utilities\StringUtilities;
Expand Down Expand Up @@ -272,6 +273,18 @@ public function parseNode(AntlersNode $node)

$node->runtimeNodes = $runtimeNodes;

if ($node->hasParameters) {
foreach ($node->runtimeNodes as $runtimeNode) {
if ($runtimeNode instanceof ModifierSeparator) {
throw ErrorFactory::makeSyntaxError(
AntlersErrorCodes::TYPE_MIXED_MODIFIER_STYLES,
$node,
'Cannot mix pipe and shorthand parameter modifier styles on the same expression. Use either "| modifier(\'value\')" or "modifier=\'value\'", but not both.'
);
}
}
}

$trimmedInner = trim($node->content);

if (ConditionPairAnalyzer::isConditionalStructure($node) && $node->name->name != 'else' && count($runtimeNodes) == 0
Expand Down
15 changes: 15 additions & 0 deletions tests/Antlers/Parser/ParserErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,19 @@ public function test_incomplete_shorthand_parameters_throws_error_two()
{
$this->assertThrowsParserError('{{ tag_name :$}}');
}

public function test_mixed_pipe_and_shorthand_modifier_throws_exception()
{
$this->assertThrowsParserError('{{ active_platforms | sort="value" }}');
}

public function test_mixed_pipe_and_shorthand_modifier_paired_throws_exception()
{
$this->assertThrowsParserError('{{ active_platforms | sort="value" }}items{{ /active_platforms }}');
}

public function test_mixed_pipe_and_shorthand_with_registered_modifier_throws_exception()
{
$this->assertThrowsParserError('{{ thing | upper="value" }}');
}
}
14 changes: 14 additions & 0 deletions tests/Antlers/Runtime/CoreModifiersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,20 @@ public function test_rawurlencode_except_slashes()
{
$this->assertSame('please%20and%20thank%20you/Mommy', $this->resultOf('{{ test_url_encode | rawurlencode_except_slashes }}'));
}

public function test_pipe_function_modifier_still_renders()
{
$data = ['items' => [['value' => 'Zebra'], ['value' => 'Apple'], ['value' => 'Mango']]];
$result = $this->renderString('{{ items | sort("value") }}{{ value }}{{ /items }}', $data, true);
$this->assertSame('applemangozebra', strtolower($result));
}

public function test_shorthand_parameter_modifier_still_renders()
{
$data = ['items' => [['value' => 'Zebra'], ['value' => 'Apple'], ['value' => 'Mango']]];
$result = $this->renderString('{{ items sort="value" }}{{ value }}{{ /items }}', $data, true);
$this->assertSame('applemangozebra', strtolower($result));
}
}

class SimpleEntryObject implements Arrayable
Expand Down
Loading