Project

General

Profile

Actions

Feature #22665

open

Implement Encoding#ascii_superset?

Feature #22665: Implement Encoding#ascii_superset?
2

Added by byroot (Jean Boussier) 1 day ago. Updated about 7 hours ago.

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

Description

Context

All Ruby encodings currently have a #ascii_compatible? metadata.

The notion of ASCII compatibility can be a bit ambiguous, in the case of Ruby it means that ASCII text can be directly concatenated / embedded inside the string.

But it doesn't mean the string can be scanned like an ASCII string. e.g. with UTF-8 if you are searching for \ (0x5c) you can do a simple 1B search,
but with some of the encodings currently marked as ASCII-compatible, like Shift-JS, you can't because 0x5c is potentially a continuation byte of another character.

This difference has resulted in some bugs / security vulnerability in the past, e.g. in Trilogy.

Proposal

I'd like Ruby to have the metadata necessary to distinguish these two distinct cases, so that's it's easier for Ruby code that is only ASCII aware to only accept encodings that are strict ASCII supersets.

The proposed method would be Encoding#ascii_superset?.

Actions

Also available in: PDF Atom