Project

General

Profile

Actions

Bug #22653

open

parse.y rb_enc_isspace incorrect usage in parse_qmark

Bug #22653: parse.y rb_enc_isspace incorrect usage in parse_qmark

Added by kddnewton (Kevin Newton) 4 days ago. Updated about 8 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:127757]

Description

This is somewhat confusing. Basically parse.y is looking for a space character after a question mark to determine if the ? is an operator or not. This matches the ASCII space character, and in some encodings matches a non-ASCII space character like 0xA0 in ISO-8859-1 (non-breaking space).

This gets weird in UTF-8. parse.y calls rb_enc_isspace(c, p->enc), but the signature is rb_enc_isspace(OnigCodePoint c, rb_encoding *enc). So it's passing a byte where the function expects a codepoint. So in UTF-8, if parse.y sees 0xA0 (an invalid codepoint sequence in UTF-8) the function will return true because that codepoint maps to non-breaking space, even though that byte doesn't.

I think this is incorrect. I think it should do one of the following:

  • decode a full codepoint in the source encoding (in UTF-8 this would be 0xC2 0xA0) to match a space
  • support only 1-byte space characters in the source encoding (like 0x20 and 0xA0 in ISO-8859-1) to match a space
  • match only ASCII space characters (only 0x20)

I'm fine with any of these options, but at minimum the current implementation is confusing.

Updated by nobu (Nobuyoshi Nakada) 2 days ago ยท Edited Actions #1 [ruby-core:127767]

kddnewton (Kevin Newton) wrote:

I think this is incorrect. I think it should do one of the following:

  • decode a full codepoint in the source encoding (in UTF-8 this would be 0xC2 0xA0) to match a space
  • support only 1-byte space characters in the source encoding (like 0x20 and 0xA0 in ISO-8859-1) to match a space
  • match only ASCII space characters (only 0x20)

This has been introduced at a25fbe3b3e53 19 years ago, I'd want to confirm the Matz's intention.
IMO, since this is the only place where this is used, I think it makes sense to use ISSPACE here, as well as the other places.

Updated by matz (Yukihiro Matsumoto) about 8 hours ago Actions #2 [ruby-core:127791]

I don't remember any particular intention. I probably replaced ISSPACE with the encoding-aware version mechanically during the M17N work.

Ruby's syntax treats only ASCII whitespace as whitespace elsewhere, and this place should be no exception. Please switch to ISSPACE as @nobu (Nobuyoshi Nakada) suggested.

Matz.

Updated by nobu (Nobuyoshi Nakada) about 8 hours ago Actions #3

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED
Actions

Also available in: PDF Atom