mirage / ocaml-uri

RFC3986 URI parsing library for OCaml
Other
97 stars 57 forks source link

Support for "data" URLs (rfc2397) #132

Closed linse closed 5 years ago

linse commented 5 years ago

I'm currently implementing the vCard format (rfc6350) and a vCard may contain photos stored as a base64 encoded data URL.

https://tools.ietf.org/html/rfc6350#section-6.2.4:

       PHOTO:data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhv
        AQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bm
        ljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0
        <...remainder of base64-encoded data...>

I'm super happy with your library so far, thank you! 👍 I tested the following example and could not get it to parse yet:

    utop # x = Uri.of_string "data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhv";;
    - : bool = false

Am I using it correctly here? If not supported yet, what would we need to implement to make the parsing of data URLs happen?

avsm commented 5 years ago

It is indeed working, but the statement you are evaluating is not an assignment; it is an equality check (x = uri) which is correctly false. You can try this:

# require "uri.top";;
# Uri.of_string "data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhv";;
Uri.t = data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhv

So this format should already be supported by Uri -- please reopen this issue if not. Looking forward to your vCard library!

linse commented 5 years ago

Ah, great, just a forgotten let, sorry about that! Phew! 👍