Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double parser returns unexpected result for the input ". " when the lexical feature is enabled #1080

Closed
evant opened this issue Nov 29, 2019 · 2 comments

Comments

@evant
Copy link

evant commented Nov 29, 2019

Prerequisites

  • Rust version : rustc 1.39.0 (4560ea788 2019-11-04)
  • nom version : 5.0.1/master
  • nom compilation features used: lexical

Test case

The number::complete::double parser returns an unexpected result when passed the input ". ". I would expect it to fail, but it returns Ok((" ", 0.0)). If the lexical feature is disabled, then the expected error of: Err(Error((" ", Digit)) is returned.

Sample repo: https://github.com/evant/nom-double-parse-issue

use nom::number::complete::double;
use nom::IResult;

fn main() {
    println!("nom double parse: {:?}", nom_double(". "));
}

fn nom_double(input: &str) -> IResult<&str, f64> {
    double(input)
}
@Alexhuszagh
Copy link
Contributor

The specific issue is here, where the complete nom parser uses lexical (which I maintain) to provide a streaming-like feature detection, which I believe is an issue here. Older versions of lexical detected the first invalid digit, which would raise an InvalidDigit if only a '.' character was found (or a '.' character follow by any non-valid digit), which was fairly amibiguous.

My new fork should correct this issue with a more modern version of lexical:
https://github.com/Alexhuszagh/nom-double-parse-issue

Newer versions, which I will shortly submit a PR for, will correctly fail with this input.

nom double parse: Ok((" ", 0.0))
lexical_043 double parse: Result { value: 0.0, error: Error { code: InvalidDigit, index: 1 } }
lexical_070 double parse: Err(Error { code: EmptyFraction, index: 0 })

Alexhuszagh added a commit to Alexhuszagh/nom that referenced this issue Jan 7, 2020
Geal pushed a commit that referenced this issue Feb 24, 2020
Patches:
- #1100
- #1080
- #1066
- And a few upstream issues.
@Geal
Copy link
Collaborator

Geal commented Feb 24, 2020

#1101 is merged, new version coming up

@Geal Geal closed this as completed Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants