rctruta opened a new issue, #28007:
URL: https://github.com/apache/datafusion/issues/28007
### Describe the bug
`docs/rustdoc_trim.py` currently matches Rust code blocks with an unanchored
regex:
```python
RUST_CODE_BLOCK_PATTERN = re.compile(r"```rust(?:,ignore)?\s*(.*?)```",
re.DOTALL)
```
This causes several rendering bugs in Sphinx docs:
1. **Corrupts 4-backtick fences containing inner `` ``` ``:** In
`docs/source/contributor-guide/testing_infrastructure.md` (lines 48–53), a ````
````rust ```` block wraps a doc-comment example containing `` /// ``` ``. The
regex matches the trailing three backticks of ```` ````rust ```` and closes
early on `` /// ``` ``, rendering `///` followed by a stray `` ``` `` line.
2. **Slices other `rust*` info strings:** Because `\s*` matches zero
characters, ```` ```rust,no_run ```` renders `,no_run` on line 1 and ````
```rustfmt ```` is rewritten into ```` ```rust ```` with `fmt` on line 1.
3. **Leaves leading blank lines after stripping `# ` setup blocks** (e.g. in
`adding-udfs.md` and `catalogs.md`), because `.strip()` runs before `# ` lines
are removed.
4. **Quadratic `O(N^2)` regex backtracking** on unclosed ```` ```rust ````
fences due to `\s*(.*?)` under `re.DOTALL`.
### To Reproduce
```python
import sys; sys.path.insert(0, "docs")
from pathlib import Path
import rustdoc_trim
snippet = "\n".join(
Path("docs/source/contributor-guide/testing_infrastructure.md")
.read_text()
.splitlines()[47:54]
)
print(rustdoc_trim.remove_hashtag_lines_in_rust_blocks(snippet))
# Prints broken `///\n```` instead of keeping `/// ```` intact
### Expected behavior
Parse fenced code blocks line-by-line following CommonMark fence rules
(matching closing fence character and minimum length, supporting `rust` /
`rust,<attr>` info strings without matching `rustfmt`, trimming blank lines
left by stripped `# ` headers, and leaving unclosed fences untouched in linear
time).
### Additional context
_No response_
### Willingness to contribute
I plan to contribute a fix for this bug independently
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]