Skip to content

[BUG] translate_imports uses blind str.replace — corrupts identifiers and string contents #26

Description

@alphacrack

File: maithili_dsl/cli.py (translate_imports)

translate_imports() still uses blind str.replace() — the exact class of bug that was fixed in the transpiler for keywords (see v0.3.0 hardening). Two verified reproductions:

Substring corruption:

Input:  उच्चगणित.कोष = १
Output: उच्चmath.कोष = १     # गणित matched inside उच्चगणित

Rewrites inside string literals:

Input:  छपाउ("गणित.")
Output: छपाउ("math.")        # user-visible output changed

Side effect: because "{module}." appearing anywhere (including strings/comments) adds the module to translated_modules, the import whitelist gets looser than intended.

Fix: reuse the word-boundary pattern machinery from transpile.py (_make_keyword_pattern) and run module translation on code regions only (after/with tokenization), not on the raw source. Track translated_modules from actual आयात statements rather than substring hits.

Tests: both repros above in tests/test_cli.py or tests/test_security.py, plus regression tests that legitimate आयात गणित + गणित.sqrt(...) still work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority: plan for next cyclearea:climaithili_dsl/cli.py and sandboxbugSomething isn't workinghelp wantedExtra attention is neededsecuritySandbox, exec safety, vulnerability-related

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions