Created
September 3, 2026 19:06
-
-
Save raeq/cd232b8ae219cc8587afaf046fcde698 to your computer and use it in GitHub Desktop.
raeq/disarm#957: is_confusable fires on printable ASCII (", |, backtick are TR39 sources) — reproduction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """is_confusable fires on printable ASCII: `"`, `|` and backtick are TR39 sources. | |
| Run from a disarm checkout (the four prose files are read relative to it) with disarm | |
| importable. Expected output on disarm 0.15.0 at da174c83 (tables Unicode 17.0.0, | |
| confusables 17.0.0): | |
| disarm 0.15.0 | |
| is_confusable('"') True | |
| is_confusable('|') True | |
| is_confusable('`') True | |
| is_confusable("'") False | |
| is_confusable('say "hi"') True | |
| is_confusable('Hello, World!') False | |
| is_confusable('{"user": "alice", "role": "admin"}') True | |
| has_anomalies('say "hi"') False | |
| normalize_confusables('"') "''" | |
| normalize_confusables('|') 'l' | |
| normalize_confusables('`') "'" | |
| repo prose (README.md, CONTRIBUTING.md, docs/user-guide/llm-pipelines.md, docs/limitations.md): | |
| 1684 non-empty lines, 1342 pure ASCII | |
| is_confusable fires on 588 of the 1342 ASCII lines | |
| 588 of those 588 contain " or | or ` | |
| 0 fire once " | ` are removed | |
| """ | |
| from __future__ import annotations | |
| import disarm | |
| FILES = ( | |
| "README.md", | |
| "CONTRIBUTING.md", | |
| "docs/user-guide/llm-pipelines.md", | |
| "docs/limitations.md", | |
| ) | |
| def main() -> None: | |
| print("disarm", disarm.__version__) | |
| for s in ['"', "|", "`", "'", 'say "hi"', "Hello, World!", '{"user": "alice", "role": "admin"}']: | |
| print(f"is_confusable({s!r})".ljust(50) + f" {disarm.is_confusable(s)}") | |
| print(f"has_anomalies('say \"hi\"') {bool(disarm.has_anomalies('say \"hi\"'))}") | |
| for c in '"|`': | |
| print(f"normalize_confusables({c!r}) {disarm.normalize_confusables(c)!r}") | |
| total = ascii_lines = fires = fires_with_mark = fires_without = 0 | |
| for path in FILES: | |
| with open(path, encoding="utf-8") as fh: | |
| for line in fh: | |
| line = line.rstrip("\n") | |
| if not line.strip(): | |
| continue | |
| total += 1 | |
| if not line.isascii(): | |
| continue | |
| ascii_lines += 1 | |
| if disarm.is_confusable(line): | |
| fires += 1 | |
| if any(c in line for c in '"|`'): | |
| fires_with_mark += 1 | |
| stripped = line.replace('"', "").replace("|", "").replace("`", "") | |
| if disarm.is_confusable(stripped): | |
| fires_without += 1 | |
| print(f"repo prose ({', '.join(FILES)}):") | |
| print(f" {total} non-empty lines, {ascii_lines} pure ASCII") | |
| print(f" is_confusable fires on {fires} of the {ascii_lines} ASCII lines") | |
| print(f" {fires_with_mark} of those {fires} contain \" or | or `") | |
| print(f" {fires_without} fire once \" | ` are removed") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment