Skip to content

date: strftime O modifier leaks as literal in C locale #11656

Closed

Description

@sylvestre

Summary

date leaks the strftime O modifier as literal text (e.g. %Om → %om) while GNU strips it in C locale. The O modifier requests "alternative numeric symbols" and is a no-op under LC_ALL=C.

Found by a fuzz_date run.

Reproduction

$ LC_ALL=C TZ=UTC /usr/bin/date -d '2024-06-15' '+%Om-%Oy-%Ol'
06-24-12
$ echo $?
0

$ LC_ALL=C TZ=UTC target/debug/coreutils date -d '2024-06-15' '+%Om-%Oy-%Ol'
%Om-%Oy-%Ol
$ echo $?
0

The E modifier is similarly affected.

Test

#[test]
fn test_date_strftime_o_modifier() {
    new_ucmd!()
        .env("LC_ALL", "C")
        .env("TZ", "UTC")
        .arg("-d")
        .arg("2024-06-15")
        .arg("+%Om-%Oy-%Ol")
        .succeeds()
        .stdout_is("06-24-12\n");
}

Activity

  1. tobyw21 commented on Apr 8, 2026

    @tobyw21

    hi @sylvestre, I found the problem, seems in coreutils/src/uu/date/src/format_modifiers.rs:82 the regex %([_0^#+-]*)(\d*)(:*[a-zA-Z]) is missing O, when I adjust to %([_O0^#+-]*)(\d*)(:*[a-zA-Z]), it prints

    $ LC_ALL=C TZ=UTC target/debug/coreutils date -d '2024-06-15' '+%Om-%Oy-%Ol'
    06-24-12
    $ echo $?
    0
    

    similar applies to E modifier.

    can I try to patch it?

  2. sylvestre commented on Apr 8, 2026

    @sylvestre
    SponsorContributorAuthor

    sure

  3. cakebaker commented on Apr 9, 2026

    @cakebaker
    Contributor

    It's unfortunately more complex and showing the modifier as literal is sometimes the expected behavior. From the documentation:

    An optional modifier can follow the optional flag and width specification. The modifiers are:

    ‘E’
    Use the locale’s alternate representation for date and time. This modifier applies to the ‘%c’, ‘%C’, ‘%x’, ‘%X’, ‘%y’ and ‘%Y’ conversion specifiers. In a Japanese locale, for example, ‘%Ex’ might yield a date format based on the Japanese Emperors’ reigns.

    ‘O’
    Use the locale’s alternate numeric symbols for numbers. This modifier applies only to numeric conversion specifiers.

    If the format supports the modifier but no alternate representation is available, it is ignored.

    And how it is currently implemented with GNU date.

    For the O modifier:

    $ for param in $(<sequences.txt); do LC_ALL=C TZ=UTC date -d "2024-06-15" "+%O$param"; done
    %O%
    %Oa
    %OA
    Jun
    June
    %Oc
    20
    15
    %OD
    15
    %OF
    24
    2024
    Jun
    00
    12
    167
     0
    12
    06
    00
    
    
    000000000
    AM
    am
    2
    12:00:00 AM
    00:00
    1718409600
    00
    
    00:00:00
    6
    23
    24
    6
    24
    %Ox
    %OX
    24
    2024
    +0000
    +00:00
    +00:00:00
    +00
    UTC
    

    And for the E modifier:

    $ for param in $(<sequences.txt); do LC_ALL=C TZ=UTC date -d "2024-06-15" "+%E$param"; done
    %E%
    %Ea
    %EA
    %Eb
    %EB
    Sat Jun 15 00:00:00 2024
    20
    %Ed
    %ED
    %Ee
    %EF
    %Eg
    %EG
    %Eh
    %EH
    %EI
    %Ej
    %Ek
    %El
    %Em
    %EM
    
    
    %EN
    AM
    am
    2
    12:00:00 AM
    00:00
    1718409600
    %ES
    
    00:00:00
    6
    %EU
    %EV
    %Ew
    %EW
    06/15/24
    00:00:00
    24
    2024
    +0000
    +00:00
    +00:00:00
    +00
    UTC
    
  4. tobyw21 commented on Apr 9, 2026

    @tobyw21

    hi @cakebaker, thanks for clarification I suppose capturing O and E modifiers in the regex is correct? Previously, without including them in the pattern, the parser essentially ignored them regardless of which specifier followed. However, the problem now lies in the parsing logic: it must distinguish which specific combinations of O or E modifiers and conversion specifiers should result in a formatted output versus those that should be ignored.

    for example, for modifier O, %OA, which is locale’s alternate representation for full weekday name, variable length, which is not applicable (the output is a string). So, for all not applicable cases like:

    %O%
    %Oa
    %OA
    %Oc
    %OD
    %OF
    %Ox
    %OX
    

    They should be ignored.
    Do we have to pre-define those cases, because from the docs:

    O: This modifier applies only to numeric conversion specifiers.

    Similar applies to modifier E but with more cases to be ignored.

    update:
    Jiff's strtime is not supporting E and O modifiers.

    The E and O locale modifiers are not supported.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions