Skip to content

to_ascii_uppercase and to_ascii_lowercase operate on non-ASCII characters #31203

Closed
@DanielKeep

Description

@DanielKeep

Behold!

#[test]
fn liar_liar_pants_on_fire() {
    use std::ascii::AsciiExt;
    assert_eq!("café".to_ascii_uppercase(), "CAFÉ");
    assert_eq!("café".to_ascii_uppercase(), "CAFé");
    assert_eq!("CAFÉ".to_ascii_lowercase(), "café");
    assert_eq!("CAFÉ".to_ascii_lowercase(), "cafÉ");
}

This is obviously silly. The problem is that this is running an ASCII-only operation on Unicode strings without actually dealing with their Unicode-ness.

These functions should either correctly deal with grapheme clusters (by ignoring them since they're not in ASCII), or document that it does not correctly handle grapheme clusters, preferably with an example (like the above).

(Actually having a standard Ascii type would be even more muchly preferable, but I suspect that's way out of scope.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions