Skip to content

Use safer harp::parse_expr() to decode file path strings #843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

DavisVaughan
Copy link
Contributor

@DavisVaughan DavisVaughan commented Jun 17, 2025

Addresses posit-dev/positron#6584

Minimal reprex was to put source(".\R\utils.R") in the console and try and request completions with tab after the utils.R.

This string actually doesn't parse. It sees \R and complains that this is an unrecognized escape sequence.

This crashed ark on both mac and windows, so you don't need a windows machine to validate this fix, but it comes up on Windows because this is the string you get when you copy out of the windows file explorer (because they hate you).

Fixed by switching out the very old r_string_decode() for our more modern tooling of parse_expr(), which is safely wrapped in a try_catch(). Related to but unaffected by #840. That PR will turn the actual error we get from an harp::Error into ParseResult::SyntaxError, but parse_expr() is insulated from that difference.

Screen.Recording.2025-06-17.at.1.42.53.PM.mov

use crate::utils::r_typeof;

// Given a quoted R string, decode it to get the string value.
pub unsafe fn r_string_decode(code: &str) -> Option<String> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, this is harp::parse_expr() with an extra check for STRSXP at the end.

@DavisVaughan DavisVaughan requested a review from juliasilge June 17, 2025 17:50
Copy link
Contributor

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working great! 🚀

  • Before this change, I could definitely see the crash myself
  • With this new build, I no longer see a crash (and no completions of course)

@DavisVaughan DavisVaughan merged commit 5ee0c69 into main Jun 18, 2025
6 checks passed
@DavisVaughan DavisVaughan deleted the fix/file-path-windows-parsing branch June 18, 2025 13:50
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants