Skip to content

Conversation

@b1ek
Copy link
Contributor

@b1ek b1ek commented Jul 15, 2025

this is for amber-lang/amber#733

also @Ph0enixKM since this is a security issue its best if you release the new version immediately once this is merged

@b1ek b1ek requested review from KrosFire, Ph0enixKM and Copilot July 15, 2025 21:43
@b1ek b1ek self-assigned this Jul 15, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adjusts the lexer so that escaped newlines are only skipped outside of line comment regions, preventing unintended behavior when parsing comments.

  • Add a check to skip escape handling if the current region begins with //
  • Update the conditional to include the region handler check

// Reaction stores the reaction of the region handler
// Have we just opened or closed some region?
let reaction = if lex_state.is_escaped {
let reaction = if lex_state.is_escaped && lex_state.region_handler.get_region().unwrap().begin != "//" {
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

Using unwrap() here can lead to a panic if get_region() returns None. Consider handling the Option explicitly or using expect() with a clear error message.

Suggested change
let reaction = if lex_state.is_escaped && lex_state.region_handler.get_region().unwrap().begin != "//" {
let reaction = if lex_state.is_escaped && lex_state.region_handler.get_region().expect("Failed to retrieve region: get_region() returned None").begin != "//" {

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

while a valid concern, it has been accessed the same way a few lines before for 10 months now. besides, i don't think that it could possibly be None in this position

// Reaction stores the reaction of the region handler
// Have we just opened or closed some region?
let reaction = if lex_state.is_escaped {
let reaction = if lex_state.is_escaped && lex_state.region_handler.get_region().unwrap().begin != "//" {
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

[nitpick] The string literal "//" is a magic value. Consider defining a constant for the line comment delimiter to improve readability and reduce duplication.

Suggested change
let reaction = if lex_state.is_escaped && lex_state.region_handler.get_region().unwrap().begin != "//" {
let reaction = if lex_state.is_escaped && lex_state.region_handler.get_region().unwrap().begin != LINE_COMMENT_DELIMITER {

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be a valid review because Heraclitus is not only for Amber and // is Amber-specific.

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

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

I think that Copilot is right here. Heraclitus is a library not only for Amber.

The proper solution I believe would be to add a field to this struct called ignore_escape. If we set that flag to true for comments then the escape key should not be affecting the parser to omit the end of comment

@b1ek
Copy link
Contributor Author

b1ek commented Jul 16, 2025

Heraclitus is a library not only for Amber.

but it literally is though? the only language that is built on it is Amber, and so far most Heraclitus issues have been related to Amber

The proper solution I believe would be to add a field to this struct called ignore_escape. If we set that flag to true for comments then the escape key should not be affecting the parser to omit the end of comment

i agree, that's a more proper way to approach this, regardless of the previous statement

@b1ek b1ek requested a review from Ph0enixKM July 16, 2025 11:01
@Ph0enixKM
Copy link
Member

@b1ek, even if Heraclitus isn’t necessarily used by other languages, it remains a core component of our compiler that is language agnostic. This separation makes it easier to maintain it

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

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

It's almost perfect. I'd leave that test though.

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

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

lgtm

@Ph0enixKM Ph0enixKM merged commit b2f7b0f into main Jul 19, 2025
1 check passed
@Ph0enixKM Ph0enixKM deleted the dont-escape-newline-in-comment branch July 19, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants