Bug 1790009, part 2 - Operator dictionary: Only accept UTF-16 strings of 1 or 2 characters. r=emilio

MathML Core specifies that operators containing a UTF-16 strings whose
length is not 1 or 2 should use the default properties [1]. This
commit removes the obsolete strings of length 3 from our operator
dictionary and tweak updateOperatorDictionary.pl to ensure it only
accepts strings of 1 or 2 characters. This also adds an early return
in LookupOperator to immediately fallback to default properties.

[1] https://w3c.github.io/mathml-core/#dfn-algorithm-to-determine-the-category-of-an-operator

Differential Revision: https://phabricator.services.mozilla.com/D157706
This commit is contained in:
Frederic Wang 2022-09-21 06:28:05 +00:00
Родитель 5a87e3e26d
Коммит 218ba23a4d
5 изменённых файлов: 84 добавлений и 7 удалений

Просмотреть файл

@ -1200,16 +1200,9 @@ operator.\u0026.prefix = lspace:0 rspace:5 # &
operator.\u002B\u002B.prefix = lspace:0 rspace:2 # ++
operator.\u002D\u002D.prefix = lspace:0 rspace:2 # --
operator.\u002E\u002E.postfix = lspace:0 rspace:0 # ..
operator.\u002E\u002E\u002E.postfix = lspace:0 rspace:0 # ...
operator.\u003B.postfix = lspace:0 rspace:0 separator # ;
operator.\u003C\u20D2.infix = lspace:5 rspace:5 # <⃒
operator.\u003E\u20D2.infix = lspace:5 rspace:5 # >⃒
operator.\u006C\u0069\u006D.prefix = lspace:0 rspace:3 movablelimits # lim
operator.\u006D\u0061\u0078.prefix = lspace:0 rspace:3 movablelimits # max
operator.\u006D\u0069\u006E.prefix = lspace:0 rspace:3 movablelimits # min
operator.\u007C\u007C\u007C.infix = lspace:2 rspace:2 stretchy fence symmetric direction:vertical # multiple character operator: |||
operator.\u007C\u007C\u007C.postfix = lspace:0 rspace:0 stretchy fence symmetric direction:vertical # multiple character operator: |||
operator.\u007C\u007C\u007C.prefix = lspace:0 rspace:0 stretchy fence symmetric direction:vertical # multiple character operator: |||
operator.\u007E.infix = lspace:2 rspace:2 stretchy direction:horizontal # ~
operator.\u0332.postfix = lspace:0 rspace:0 stretchy accent direction:horizontal # _
operator.\u03F6.infix = lspace:5 rspace:5 # greek reversed lunate epsilon symbol

Просмотреть файл

@ -317,6 +317,12 @@ bool nsMathMLOperators::LookupOperator(const nsString& aOperator,
NS_ASSERTION(aFlags && aLeadingSpace && aTrailingSpace, "bad usage");
NS_ASSERTION(aForm > 0 && aForm < 4, "*** invalid call ***");
// Operator strings must be of length 1 or 2 in UTF-16.
// https://w3c.github.io/mathml-core/#dfn-algorithm-to-determine-the-category-of-an-operator
if (aOperator.IsEmpty() || aOperator.Length() > 2) {
return false;
}
if (!gGlobalsInitialized) {
InitOperatorGlobals();
}

Просмотреть файл

@ -134,6 +134,13 @@ if ($ARGV[0] eq "check") {
@moz_keys = (keys %moz_hash);
# check the validity of our private data
while ($key = pop(@moz_keys)) {
if ($key =~ /\\u.+\\u.+\\u.+/) {
$valid = 0;
$nb_errors++;
print $file_syntax_errors "error: \"$key\" has more than 2 characters\n";
}
@moz = @{ $moz_hash{$key} };
$entry = &generateEntry($key, @moz);
$valid = 1;

Просмотреть файл

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Spacing of empty and three-char operators (reference)</title>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<style>
math {
font: 50px/1 Ahem;
}
mn:first-child {
color: blue;
}
mn:last-child {
color: yellow;
}
</style>
</head>
<body>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em">_</mo><mn>_</mn></math></p>
<p>The spacing after the blue squares and before the yellow squares should be the same as the above reference:</p>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em"><!-- empty --></mo><mn>_</mn></math></p>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em">...</mo><mn>_</mn></math></p>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em">lim</mo><mn>_</mn></math>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em">max</mo><mn>_</mn></math>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em">min</mo><mn>_</mn></math>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em">|||</mo><mn>_</mn></math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Spacing of empty and three-char operators</title>
<link rel="help" href="https://w3c.github.io/mathml-core/#operator-fence-separator-or-accent-mo">
<link rel="help" href="https://w3c.github.io/mathml-core/#operator-dictionary">
<meta name="assert" content="Verifies that empty and three-char operators use the default spacing.">
<link rel="match" href="operator-dictionary-empty-and-three-chars-ref.html">
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<style>
math {
font: 50px/1 Ahem;
}
mn:first-child {
color: blue;
}
mn:last-child {
color: yellow;
}
</style>
</head>
<body>
<p><math><mn>_</mn><mo lspace="0.2777777777777778em" rspace="0.2777777777777778em">_</mo><mn>_</mn></math></p>
<p>The spacing after the blue squares and before the yellow squares should be the same as the above reference:</p>
<p><math><mn>_</mn><mo><!-- empty --></mo><mn>_</mn></math></p>
<p><math><mn>_</mn><mo>...</mo><mn>_</mn></math></p>
<p><math><mn>_</mn><mo>lim</mo><mn>_</mn></math>
<p><math><mn>_</mn><mo>max</mo><mn>_</mn></math>
<p><math><mn>_</mn><mo>min</mo><mn>_</mn></math>
<p><math><mn>_</mn><mo>|||</mo><mn>_</mn></math>
<script src="/mathml/support/feature-detection.js"></script>
<script>MathMLFeatureDetection.ensure_for_match_reftest("has_operator_spacing");</script>
</body>
</html>