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

未关闭 适合新手
#959 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
accessibility

调研方向

从 src/canonicalize.rs 中的 split_apart_pseudo_scripts 和报告中无法通过的 MathML 示例开始。issue 包含针对单字符标识符的保护措施提案,以及一个名为 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 小时
30 天内合并 PR
84

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

daisy/MathCAT 的其他 Issue

查看 daisy/MathCAT 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。