Skip to content

validation done by parse and safeApply functions of Uri #2617

Description

@odavy37

Hi,

I cannot understand the parse and safeApply functions of Uri

The following unit tests are OK.
import sttp.model.Uri
// scheme:[//[user:password@]host[:port]]path[?query][#fragment]
assert(Uri.safeApply("http://example.com/path?query=123#frag").isRight)
assert(Uri.safeApply("mailto:user@example.com").isRight)
assert(Uri.safeApply("ftp://user:pass@ftp.example.org:21/files").isRight)

But the following unit tests are KO : do I use correctly the API to validate an uri ?
// 1. Missing scheme
assert(Uri.safeApply("example.com/path").isLeft)
// 2. Invalid characters (unescaped)
assert(Uri.safeApply("http://example.com/space here").isLeft)
// 3. Invalid port number
assert(Uri.safeApply("http://example.com:999999/path").isLeft)
// 4. Malformed IPv6 address
assert(Uri.safeApply("http://[2001:db8::12345]/path").isLeft)

regards,

OD

Activity

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

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