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
7 changes: 7 additions & 0 deletions stack/cas/parsingrules/601_castext.filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public function filter(MP_Node $ast, array &$errors, array &$answernotes, stack_
$compiled = $compiled->statement;
}
$compiled->position['castext'] = true;
if ($compiled instanceof MP_String) {
// An inline-CASText fragment cannot be flat, as injections of such could not be distinguished
// from string injections. For this reason we tag it with a marker to stop simplification.
// And make it non flat if it already is.
$compiled = new MP_List([new MP_String('%root'), $compiled]);
}
$compiled->position['inline-castext'] = true;
$node->parentnode->replace($node, $compiled);
return false;
} else if ($node->name instanceof MP_Identifier && $node->name->value === 'castext_concat') {
Expand Down
4 changes: 2 additions & 2 deletions stack/cas/parsingrules/602_castext_simplifier.filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ public function filter(MP_Node $ast, array &$errors, array &$answernotes, stack_
$node->items[0]->value === 'demoodle' ||
$node->items[0]->value === 'htmlformat')
) {
if ($node->items[0]->value === '%root' && count($node->items) === 2 && $node->items[1] instanceof MP_String) {
// A concatenation of a single string, can be removed. If %root.
if ($node->items[0]->value === '%root' && count($node->items) === 2 && $node->items[1] instanceof MP_String && !(isset($node->position['inline-castext']) && $node->position['inline-castext'])) {
// A concatenation of a single string, can be removed. If %root and not inline-CASText.
$node->parentnode->replace($node, $node->items[1]);
return false;
}
Expand Down
Loading