Repository navigation
feat(script): load a script file into the Script pane (#2397) - #2401
jgregoriorincon wants to merge 1 commit into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
| /// A script file the shell's picker read for Load…, kept for [`RustGisApp::logic`] to open once | ||
| /// the inbox is read. A file that isn't UTF-8 text, or one landing while a run is under | ||
| /// way, is refused and said, and the pane's script stays. | ||
| pub(crate) fn script_picked(app: &mut RustGisApp, bytes: &[u8]) -> Result<Value, String> { |
There was a problem hiding this comment.
Performance / size limit (medium confidence). In the browser, the 1 MB check runs only after the whole picked file has been read into memory. read_together in apps/rustgis-web/src/web.rs (around line 489) reads each file with parts::read_file before this function sees it, and only the shortcut purpose is refused on file.size() before that read. A multi-hundred-MB file picked for Load… is therefore fully read into wasm memory and then refused.
Suggested fix: in read_together, extend the pre-read size check from shortcut to the script purpose (for example let script = mark == rustgis_ui_egui::SCRIPT_PICK; and if (shortcut || script) && file.size() > …), with the same notice pattern. Give the script limit its own notice, or refuse with the script message, so the user is told why. The new a_script_from_the_shells_picker_opens_in_the_pane test calls open_picked directly, so it never exercises this path. A test that covers the size refusal before the read would be useful.
| if bytes.len() > SCRIPT_FILE_MAX_BYTES { | ||
| return Err(tl!("The script file is larger than 1 MB").to_string()); | ||
| } | ||
| std::str::from_utf8(bytes).map(str::to_owned).map_err(|_| tl!("The file isn't UTF-8 text").to_string()) |
There was a problem hiding this comment.
Bug (medium-high confidence): a UTF-8 byte-order mark makes the first line fail. Windows Notepad and some other editors write .txt files with a UTF-8 BOM (EF BB BF). That BOM decodes to U+FEFF, which is not Unicode White_Space, so str::trim() in script_line (crates/engine/src/parameters.rs:26) doesn't remove it. The first command then becomes \u{feff}map.zoomFull, and the run fails on line 1 with an unknown-command error. The file is refused as a valid script even though it is UTF-8. The other text readers in crates/data/src/io.rs already strip a leading BOM.
Suggested fix: strip the BOM before the UTF-8 check. The replacement below is for this line only:
| std::str::from_utf8(bytes).map(str::to_owned).map_err(|_| tl!("The file isn't UTF-8 text").to_string()) | |
| let bytes = bytes.strip_prefix(b"\xEF\xBB\xBF").unwrap_or(bytes); | |
| std::str::from_utf8(bytes).map(str::to_owned).map_err(|_| tl!("The file isn't UTF-8 text").to_string()) |
Please add a test for it: a BOM-prefixed file should load and run, with no notice. The same file without the BOM should give the same script.
Code reviewBugs
Security
Performance
Quality (grouped nits; left for the release quality pass)
AGENTS.md
Prior review threads: none on this PR, so no earlier concerns were left alone. Change sizeCompared with the base branch: the whole PR against main (merge base 7e9718e to PR head 9ad95ac).
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. |
Summary
The Script pane gets a Load… button beside Commands…, so a script kept on disk no longer has to be pasted in by hand.
*.txt, All files). In the browser and on Android/iOS it asks the shell's picker through a new"script"purpose, whose file comes back marked withSCRIPT_PICK, the same way shortcut files are routed.open_script), so Ctrl+Z (⌘+Z) brings the previous script back.open_picked, which has noegui::Context, so the text waits inWorkflow.script_pickedandRustGisApp::logicopens it right after reading the inbox, in the same frame.Surfaces: desktop, browser and phone. The CLI, Python and the assistant are not affected: Load… is a pane-local action, like Clear, not a command.
Testing
analysispane::tests::load_reads_a_script_file_in_place_of_the_panes(desktop picker: cancel, non-UTF-8 file, valid file, Ctrl+Z restores the old script, disabled during a run) andanalysispane::tests::a_script_from_the_shells_picker_opens_in_the_pane(shell picker:"script"purpose, cancel, non-UTF-8, over 1 MB, valid file, refused during a run). The mobilemark("script")mapping is covered ina_dxf_request_keeps_its_id_in_its_mark.cargo fmt --all --check,cargo clippy -p rustgis-ui-egui -p rustgis-mobile -p rustgis-web --all-targets -- -D warnings,cargo nextest runon the workspace (7692 passed, 26 skipped), doctests andcargo xtask layers: all pass.cargo check -p rustgis-web --target wasm32-unknown-unknown: passes.UI evidence
Before / after: the Script pane's buttons.
Related issue
Closes #2397