Skip to content

validation done by parse and safeApply functions of Uri #2617

@odavy37

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:[email protected]").isRight)
assert(Uri.safeApply("ftp://user:[email protected]: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

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