Skip to content
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

Fix crash caused by trailing spaces #103825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JulianHeuser
Copy link
Contributor

@JulianHeuser JulianHeuser commented Mar 8, 2025

Fixes #103797
Issue introduced in #101319

(Also is mildly more efficient since it isn't redundantly splitting twice)

@JulianHeuser JulianHeuser requested a review from a team as a code owner March 8, 2025 17:06
@tdaven
Copy link
Contributor

tdaven commented Mar 8, 2025

I can confirm that this fixes #103797 for me.

Comment on lines +155 to +160
Vector<String> str_stripped_split = str.strip_edges().split_spaces();
if (!str_stripped_split.is_empty() &&
str_stripped_split[0] != "#region" &&
str_stripped_split[0] != "#endregion") {
match = false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Vector<String> str_stripped_split = str.strip_edges().split_spaces();
if (!str_stripped_split.is_empty() &&
str_stripped_split[0] != "#region" &&
str_stripped_split[0] != "#endregion") {
match = false;
}
String stripped_str = str.strip_edges();
if (!stripped_str.begins_with("#region") && !stripped_str.begins_with("#endregion")) {
match = false;
}

Copy link
Contributor Author

@JulianHeuser JulianHeuser Mar 9, 2025

Choose a reason for hiding this comment

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

This works but undoes the original fix where this bug was introduced.
For example, "#region" and "#endregion" here are highlighted, but don't actually create a region you can collapse or expand.
image
We need to check for whitespace after region/endregion to fix this.

To improve this code's efficiency, it would be nice if get_spaces had a maxsplit parameter like the normal split function does, but I don't know if its worth adding that extra functionality just for this.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we can use the maxsplit parameter since we are only checking the 0th substring.

Or alternatively we could extract the alphanumeric identifier after the #. Since the current version does not take into account cases like #region:Name. I think we should add methods like String.get_{ascii,unicode}_identifier(from: int = 0) -> 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.

Is there a source for what characters should be after #region or is that up in the air? The only examples the docs show are with whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editor crashes when entering simple if statement
4 participants