Skip to content

Document (or fix?) the fact that escaped() succeeds on empty inputs #1735

Open
@LunarLambda

Description

Combinators such as many1 explicitly state they fail if the input parser accepts empty inputs. For this reason, most parsers like is_not fail on empty inputs.

However, escaped immediately returns Ok when given an empty input without even attempting to run the inner parser, which otherwise would correctly return an error, which escaped would then correctly pass up when it detects that the error was due to empty input. I'm unsure whether this is intentional or an oversight, as a code path doing the right thing does exist, but is not triggered.

This leads to an issue where wrapping an existing parser in escaped can change its behaviour:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e37a7669c47bed92d6853e788ba0725b

Workaround in my case seems to be wrapping the escaped in verify(..., |s: &str| !s.is_empty())

  • Rust version : 1.76.0
  • nom version : 7.13
  • nom compilation features used: default

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