Crash with the ordinal indicators `º`/`ª` in `mi`

オープン 初心者向け
#959 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
accessibility

調査の方向性

src/canonicalize.rs の split_apart_pseudo_scripts と、失敗すると報告された MathML の例から始めてください。issue には、1 文字の識別子に対するガードの提案と、pseudo_script_single_char_mi という名前の回帰テストが含まれています。修正を確認するために cargo test を実行してください。例でクラッシュが起きなくなり、回帰テストが成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

In Spanish, ordinals are written with a period and the ordinal indicator: 1.º, 2.ª (U+00BA, U+00AA; not the degree sign). When the indicator comes as an mi on its own, MathCAT crashes, in any language:

<math><mn>1</mn><mo>.</mo><mi>º</mi></math>
<math><mn>1.</mn><mi>º</mi></math>
<math><mn>2</mn><mo>.</mo><mi>ª</mi></math>

All give index out of bounds at src/canonicalize.rs:404.

Cause and proposed patch: split_apart_pseudo_scripts pairs each char with the next one, so a single char gives no pairs and replace_children is called with an empty list. Tested: cargo test passes; adds the test pseudo_script_single_char_mi.

diff --git a/src/canonicalize.rs b/src/canonicalize.rs
index 1e3936f8..00a5165b 100644
--- a/src/canonicalize.rs
+++ b/src/canonicalize.rs
@@ -1520,7 +1520,8 @@ impl CanonicalizeContext {
 
 			let text = as_text(mi);
 			// debug!("split_apart_pseudo_scripts: start text=\"{text}\"");
-			if !text.chars().any(is_pseudo_script_char) || IS_DEGREES_C_OR_F.is_match(as_str!(text)) {
+			if !text.chars().any(is_pseudo_script_char) || IS_DEGREES_C_OR_F.is_match(as_str!(text)) ||
+			   text.chars().nth(1).is_none() {		// a single char (e.g., "º") has nothing to split
 				return None;
 			}
 
@@ -7085,6 +7086,14 @@ mod canonicalize_tests {
         are_strs_canonically_equal_result(test_str, target_str, &[])
 	}
 
+	#[test]
+    fn pseudo_script_single_char_mi() -> Result<()> {
+        // used to crash (index out of bounds in replace_children)
+        let test_str = "<math><mn>1</mn><mi>º</mi></math>";
+        let target_str = "<math><mrow data-changed='added'><mn>1</mn><mo data-changed='added'>&#x2062;</mo><mi>º</mi></mrow></math>";
+        are_strs_canonically_equal_result(test_str, target_str, &[])
+	}
+
 	#[test]
     fn prescript_only() -> Result<()> {
         let test_str = "<math><msub><mtext/><mn>92</mn></msub><mi>U</mi></math>";
主要言語
Rust
スター
130
フォーク
96
平均マージ
1日 1時間
マージ済み PR(30日)
84

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

daisy/MathCAT のほかの issue

daisy/MathCAT の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。