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 #header_fld_name to handle quoted strings correctly #315

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

taku0
Copy link
Contributor

@taku0 taku0 commented Aug 31, 2024

Summary

If a header field name is quoted, ResponseParser#header_fld_name drops the closing quotation mark.

Reprodusing code

parser = Net::IMAP::ResponseParser.new

parser.instance_variable_set("@str", %Q|"CONTENT-LOCATION")|)
parser.instance_variable_set("@pos", 0)
parser.instance_variable_set("@lex_state", Net::IMAP::ResponseParser::EXPR_BEG)

parser.send(:header_fld_name)

Expected: "\"CONTENT-LOCATION\""
Actual: "\"CONTENT-LOCATION"

Cause

header_fld_name extract the raw encoded value using @str and @pos. header_fld_name expects astring to lookahead a space or a closing parenthesis but if the field name is quoted, it calls string method and it doesn't lookahead a token.

Fix

Adjust the range to extract depending on whether a token is looked ahead or not.

Copy link
Collaborator

@nevans nevans left a comment

Choose a reason for hiding this comment

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

Good catch. Thanks! I'll merge and release it on Monday or Tuesday.

Could you add a simple test case to test/net/imap/fixtures/response_parser/fetch_responses.yml? If you add the test case without any "expected" value, the test runner will print out the actual parsed result, for you to inspect and copy/paste into the yaml. Thanks!

@taku0
Copy link
Contributor Author

taku0 commented Sep 1, 2024

I have amended the commit with a test case.

@nevans nevans merged commit 74a39b9 into ruby:master Sep 2, 2024
9 checks passed
@nevans
Copy link
Collaborator

nevans commented Sep 4, 2024

@taku0 v0.4.16 has been released. Thanks again!

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

Successfully merging this pull request may close these issues.

2 participants