Skip to content

Conversation

@kishikawakatsumi
Copy link
Contributor

This pull request fixes a problem where escaping fails when a pound sign follows a sequence of double quotes or backslashes.

As shown in the added test case, foobar""# and foobar\\# require two pound signs as delimiter for escaping, but the current implementation only adds one pound sign, resulting in an incorrect string literal.

The reason for this is that a sequence of double quotes or backslashes will stop counting pound signs if they are not followed by a pound sign.

If a double quotation mark or backslash is followed by a double quotation mark or backslash, it must continue in pound sign counting mode.

…follows a sequence of double quotes or backslashes.

This pull request fixes a problem where escaping fails when a pound sign follows a sequence of double quotes or backslashes.

As shown in the added test case, `foobar""#` and `foobar\\#` require two pound signs as delimiter for escaping, but the current implementation only adds one pound sign, resulting in an incorrect string literal.

The reason for this is that a sequence of double quotes or backslashes will stop counting pound signs if they are not followed by a pound sign.

If a double quotation mark or backslash is followed by a double quotation mark or backslash, it must continue in pound sign counting mode.
Comment on lines 291 to 292
countingPounds = true
requiresEscaping = true
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn’t this just be continue? AFAICT countingPounds = true is already true because of the case condition and AFAICT requiresEscaping = true is already true because we entered case (false, "\""), (false, "\\"): before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, it is better to use continue. Fixed.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thank you!

@ahoppen
Copy link
Member

ahoppen commented Jun 20, 2023

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Jun 20, 2023

@kishikawakatsumi Would you mind also opening a cherry-pick PR to release/5.9? I think it’s worth fixing this formatting issue in SwiftSyntax 509.

@kishikawakatsumi
Copy link
Contributor Author

@ahoppen Sure. #1821

@ahoppen
Copy link
Member

ahoppen commented Jul 11, 2023

Oh, sorry. I completely forgot to merge this.

@ahoppen ahoppen merged commit c217d98 into swiftlang:main Jul 11, 2023
@kishikawakatsumi kishikawakatsumi deleted the literal branch July 11, 2023 17:44
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.

2 participants