'names' => [ 2 => null ],
'min' => 2,
'max' => 2,
- ]
+ ],
+ '-{' => [
+ 'end' => '}-',
+ 'names' => [ 1 => null ],
+ 'min' => 1,
+ 'max' => 1,
+ ],
];
/**
* @return string
*/
public function preprocessToXml( $text, $flags = 0 ) {
+ global $wgDisableLangConversion;
+
$forInclusion = $flags & Parser::PTD_FOR_INCLUSION;
$xmlishElements = $this->parser->getStripList();
$stack = new PPDStack;
$searchBase = "[{<\n"; # }
+ if ( !$wgDisableLangConversion ) {
+ $searchBase .= '-';
+ }
+
// For fast reverse searches
$revText = strrev( $text );
$lengthText = strlen( $text );
break;
}
} else {
- $curChar = $text[$i];
+ $curChar = $curTwoChar = $text[$i];
+ if ( ( $i + 1 ) < $lengthText ) {
+ $curTwoChar .= $text[$i + 1];
+ }
if ( $curChar == '|' ) {
$found = 'pipe';
} elseif ( $curChar == '=' ) {
} else {
$found = 'line-start';
}
+ } elseif ( $curTwoChar == $currentClosing ) {
+ $found = 'close';
+ $curChar = $curTwoChar;
} elseif ( $curChar == $currentClosing ) {
$found = 'close';
+ } elseif ( isset( $this->rules[$curTwoChar] ) ) {
+ $curChar = $curTwoChar;
+ $found = 'open';
+ $rule = $this->rules[$curChar];
} elseif ( isset( $this->rules[$curChar] ) ) {
$found = 'open';
$rule = $this->rules[$curChar];
+ } elseif ( $curChar == '-' ) {
+ $found = 'dash';
} else {
# Some versions of PHP have a strcspn which stops on null characters
# Ignore and continue
// input pointer.
} elseif ( $found == 'open' ) {
# count opening brace characters
- $count = strspn( $text, $curChar, $i );
+ $curLen = strlen( $curChar );
+ $count = ( $curLen > 1 ) ? 1 : strspn( $text, $curChar, $i );
# we need to add to stack only if opening brace count is enough for one of the rules
if ( $count >= $rule['min'] ) {
# Add literal brace(s)
$accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
}
- $i += $count;
+ $i += $curLen * $count;
} elseif ( $found == 'close' ) {
$piece = $stack->top;
# lets check if there are enough characters for closing brace
$maxCount = $piece->count;
- $count = strspn( $text, $curChar, $i, $maxCount );
+ $curLen = strlen( $curChar );
+ $count = ( $curLen > 1 ) ? 1 : strspn( $text, $curChar, $i, $maxCount );
# check for maximum matching characters (if there are 5 closing
# characters, we will probably need only 3 - depending on the rules)
# No matching element found in callback array
# Output a literal closing brace and continue
$accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
- $i += $count;
+ $i += $curLen * $count;
continue;
}
$name = $rule['names'][$matchingCount];
}
# Advance input pointer
- $i += $matchingCount;
+ $i += $curLen * $matchingCount;
# Unwind the stack
$stack->pop();
$stack->getCurrentPart()->eqpos = strlen( $accum );
$accum .= '=';
++$i;
+ } elseif ( $found == 'dash' ) {
+ $accum .= '-';
+ ++$i;
}
}
* @return PPNode_Hash_Tree
*/
public function preprocessToObj( $text, $flags = 0 ) {
+ global $wgDisableLangConversion;
+
$tree = $this->cacheGetTree( $text, $flags );
if ( $tree !== false ) {
$store = json_decode( $tree );
$stack = new PPDStack_Hash;
$searchBase = "[{<\n";
+ if ( !$wgDisableLangConversion ) {
+ $searchBase .= '-';
+ }
+
// For fast reverse searches
$revText = strrev( $text );
$lengthText = strlen( $text );
break;
}
} else {
- $curChar = $text[$i];
+ $curChar = $curTwoChar = $text[$i];
+ if ( ( $i + 1 ) < $lengthText ) {
+ $curTwoChar .= $text[$i + 1];
+ }
if ( $curChar == '|' ) {
$found = 'pipe';
} elseif ( $curChar == '=' ) {
} else {
$found = 'line-start';
}
+ } elseif ( $curTwoChar == $currentClosing ) {
+ $found = 'close';
+ $curChar = $curTwoChar;
} elseif ( $curChar == $currentClosing ) {
$found = 'close';
+ } elseif ( isset( $this->rules[$curTwoChar] ) ) {
+ $curChar = $curTwoChar;
+ $found = 'open';
+ $rule = $this->rules[$curChar];
} elseif ( isset( $this->rules[$curChar] ) ) {
$found = 'open';
$rule = $this->rules[$curChar];
+ } elseif ( $curChar == '-' ) {
+ $found = 'dash';
} else {
# Some versions of PHP have a strcspn which stops on null characters
# Ignore and continue
// input pointer.
} elseif ( $found == 'open' ) {
# count opening brace characters
- $count = strspn( $text, $curChar, $i );
+ $curLen = strlen( $curChar );
+ $count = ( $curLen > 1 ) ? 1 : strspn( $text, $curChar, $i );
# we need to add to stack only if opening brace count is enough for one of the rules
if ( $count >= $rule['min'] ) {
# Add literal brace(s)
self::addLiteral( $accum, str_repeat( $curChar, $count ) );
}
- $i += $count;
+ $i += $curLen * $count;
} elseif ( $found == 'close' ) {
$piece = $stack->top;
# lets check if there are enough characters for closing brace
$maxCount = $piece->count;
- $count = strspn( $text, $curChar, $i, $maxCount );
+ $curLen = strlen( $curChar );
+ $count = ( $curLen > 1 ) ? 1 : strspn( $text, $curChar, $i, $maxCount );
# check for maximum matching characters (if there are 5 closing
# characters, we will probably need only 3 - depending on the rules)
# No matching element found in callback array
# Output a literal closing brace and continue
self::addLiteral( $accum, str_repeat( $curChar, $count ) );
- $i += $count;
+ $i += $curLen * $count;
continue;
}
$name = $rule['names'][$matchingCount];
}
# Advance input pointer
- $i += $matchingCount;
+ $i += $curLen * $matchingCount;
# Unwind the stack
$stack->pop();
$accum[] = [ 'equals', [ '=' ] ];
$stack->getCurrentPart()->eqpos = count( $accum ) - 1;
++$i;
+ } elseif ( $found == 'dash' ) {
+ self::addLiteral( $accum, '-' );
+ ++$i;
}
}
</p>
!! end
+!! test
+T146304: Don't break template parsing if language converter markup is in the parameter.
+!! options
+language=sr variant=sr-ec
+!! wikitext
+{{echo|-{R|foo}-}}
+!! html/php
+<p>foo
+</p>
+!! end
+
# FIXME: This test is currently broken in the PHP parser (bug 52661)
!! test
Don't break image parsing if language converter markup is in the caption.