Skip to content

"TRUE" does not parse into boolean #101870

Closed
@djensen1997

Description

@djensen1997

Summary of the issue

When taking input into my program, I ran into a situation where the user would pass "TRUE" into a field that I was attempting to use the .parse() method into a boolean:

fn input(value: &str) -> Result<(), MyErrorType> {
  let new_val: bool = value.parse().map_err(|_| MyErrorType{})?;
  Ok(())
}

when I split this specific line of code into a fresh rust project:

fn main() {
    let x: bool = "TRUE".parse().expect("NOPE");
}

I got the output:
thread 'main' panicked at 'NOPE: ParseBoolError', src/main.rs:20:34

What I expect to happen

I would expect rust to see the string value "TRUE" and read that as a boolean with the value true

What actually happens

I am getting an error return with MyErrorType

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions