mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-28 01:10:09 +00:00
Fix broken/incomplete regex patterns in TexNode::texContainsFunc
I compared with
6c6988c4f6/lib/astutil.js
and found two mistakes:
* Missing space at the end of the color regex.
* Not enough backslash escaping in the last regex.
Note how the code in lines #116 and #130 is now identical.
Change-Id: I13b75ad4a1e4da0766c0d73b8786b21865945697
This commit is contained in:
parent
f09ce3134b
commit
566944c42d
|
@ -120,14 +120,14 @@ class TexNode {
|
|||
|
||||
// special case #3: \\color, \\pagecolor, \\definecolor
|
||||
$matches = [];
|
||||
$m = preg_match( '/^(\\\\(color|pagecolor|definecolor))/', $t, $matches );
|
||||
$m = preg_match( '/^(\\\\(?:page|define)?color) /', $t, $matches );
|
||||
if ( $m == 1 ) {
|
||||
return self::match( $target, $matches[1] );
|
||||
}
|
||||
|
||||
// special case #4: \\mathbb, \\mathrm
|
||||
$matches = [];
|
||||
$m = preg_match( '/^(\\\\math..) \{(\\.*)}$/', $t, $matches );
|
||||
$m = preg_match( '/^(\\\\math..) \{(\\\\.*)}$/', $t, $matches );
|
||||
if ( $m == 1 ) {
|
||||
return self::match( $target, $matches[1] ) ?: self::match( $target, $matches[2] );
|
||||
}
|
||||
|
|
|
@ -137,21 +137,17 @@ class TexNodeTest extends MediaWikiUnitTestCase {
|
|||
[ '\\mismatch', '\\mbox{\\somefunc}', false ],
|
||||
[ '\\somefunc', '\\mbox {\\somefunc}', false ],
|
||||
[ '\\color', '\\color' ],
|
||||
// FIXME: This might be to relaxed; maybe add a \b to the regex?
|
||||
[ '\\color', '\\colorscheme because the rest is ignored' ],
|
||||
[ '\\color', '\\color the rest is ignored' ],
|
||||
[ '\\pagecolor', '\\pagecolor' ],
|
||||
[ '\\definecolor', '\\definecolor' ],
|
||||
[ '\\mathbb', '\\mathbb {}' ],
|
||||
[ '\\mathbb', '\\mathbb {}', false ],
|
||||
[ '\\mathbb', '\\mathbb {A}', false ],
|
||||
[ '\\mathbb', '\\mathbb {foo}', false ],
|
||||
[ '\\mathbb', '\\mathbb{}', false ],
|
||||
|
||||
// FIXME: I believe these don't make sense; mistake in the regex?
|
||||
[ '\\mathbb', '\\mathbb {.}' ],
|
||||
[ '\\mathbb', '\\mathbb {..........}' ],
|
||||
// FIXME: I believe these should both succeed
|
||||
[ '\\mathbb', '\\mathbb {\\foo}', false ],
|
||||
[ '\\foo', '\\mathbb {\\foo}', false ],
|
||||
[ '\\mathbb', '\\mathbb {.}', false ],
|
||||
[ '\\mathbb', '\\mathbb {..........}', false ],
|
||||
[ '\\mathbb', '\\mathbb {\\foo}' ],
|
||||
[ '\\foo', '\\mathbb {\\foo}' ],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue