Skip to content

🐛 Fix bug (introduced by #712) testing if string is quotable#723

Merged
nevans merged 1 commit into
masterfrom
fix-unquotable-chars-regexp
Jul 23, 2026
Merged

🐛 Fix bug (introduced by #712) testing if string is quotable#723
nevans merged 1 commit into
masterfrom
fix-unquotable-chars-regexp

Conversation

@nevans

@nevans nevans commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

This bug was introduced by a742a10, as part of #712. When I extracted the UNQUOTABLE_CHARS regexp into a constant, I didn't copied it exactly. It was converted from a character class into a sequence of bytes:

    # It should've been this:
    UNQUOTABLE_CHARS = /[\r\n]/n
    # But I incorrectly copied it as this:
    UNQUOTABLE_CHARS = /\r\n/n

If that regexp were the only guard, this regexp would've allowed CRLF injections! Fortunately, quoted strings are now sent using Net::IMAP::QuotedString (since #698, released in v0.6.4.1), and that does correctly validate that the input is a valid quoted string. So, the string isn't sent as invalid quoted data.

Unfortunately, this does result in an exception for strings that could be valid literals. And, because it crashes while sending command arguments, rather than during validation, the connection will be broken.

This bug was introduced by a742a10.  When I extracted the
`UNQUOTABLE_CHARS` regexp into a constant, I didn't copied it exactly.
It was converted from a character class into a sequence of bytes:
```ruby
    # It should've been this:
    UNQUOTABLE_CHARS = /[\0\r\n]/n
    # But I incorrectly copied it as this:
    UNQUOTABLE_CHARS = /\0\r\n/n
```

If that regexp were the only guard, this regexp would've allowed CRLF
injections!  Fortunately, quoted strings are now sent using
`Net::IMAP::QuotedString` (since #698, released in v0.6.4.1), and that
_does_ correctly validate that the input is a valid quoted string.  So,
the string isn't _sent_ as invalid quoted data.

Unfortunately, this does result in an exception for strings that could
be valid literals.  And, because it crashes while sending command
arguments, rather than during validation, the connection will be broken.
@nevans
nevans merged commit 416ada4 into master Jul 23, 2026
34 checks passed
@nevans
nevans deleted the fix-unquotable-chars-regexp branch July 23, 2026 19:40
@nevans nevans added the bug Something isn't working label Jul 23, 2026
@nevans nevans changed the title 🐛 Fix bug in #712, testing if string is quotable 🐛 Fix bug (introduced by #712) testing if string is quotable Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant