Describe the bug
An exception is thrown when trying to parse a 'data:' URL that has empty data. This happens for either percent encoded or Base64 encoded forms of the data URL.
In RFC 2397 which describes the data URL scheme, it appears to allow URLs with empty data, such as "data:," or "data:;base64,".
It's a bit of an edge case, so I had a search around about this and came across a couple of things:
Wikipedia's article on data URLs mentions 'The minimal data URI is data:,, consisting of the scheme, no media-type, and zero-length data.' and 'The data, separated from the preceding part by a comma (,). The data is a sequence of zero or more octets represented as characters.'
io.lemonlabs.uri.parsing.UriParsingException: Invalid Data Url could not be parsed. Error(6,NonEmptyList(ExpectedFailureAt(6,)))
at io.lemonlabs.uri.parsing.UrlParser.$anonfun$mapParseError$1(UrlParser.scala:381)
at scala.util.Success.flatMap(Try.scala:258)
at io.lemonlabs.uri.parsing.UrlParser.mapParseError(UrlParser.scala:379)
at io.lemonlabs.uri.parsing.UrlParser.parseDataUrl(UrlParser.scala:408)
at io.lemonlabs.uri.parsing.UrlParser$.parseDataUrl(UrlParser.scala:477)
at io.lemonlabs.uri.DataUrl$.parseTry(Uri.scala:1308)
at io.lemonlabs.uri.DataUrl$.parse(Uri.scala:1302)
... 40 elided
Also, I think as a consequence of this and how the parsing work under the hood, using Url.parse with an empty data URL doesn't produce a DataUrl as would be expected.
e.g. the following two lines
Whereas any other non-empty data URL gives the result:
val res0: String = DataUrl
This looked like it might just require a small tweak in the code so I tried my hand at a potential fix. I'll raise a PR for it shortly in case it's helpful and of course if you agree that it's even a bug.
Describe the bug An exception is thrown when trying to parse a 'data:' URL that has empty data. This happens for either percent encoded or Base64 encoded forms of the data URL.
In RFC 2397 which describes the data URL scheme, it appears to allow URLs with empty data, such as "data:," or "data:;base64,".
It's a bit of an edge case, so I had a search around about this and came across a couple of things:
To Reproduce In version 4.0.2 (and I think also earlier versions from 2.x.x onwards), either of these lines:
... will throw this exception:
Also, I think as a consequence of this and how the parsing work under the hood, using
Url.parse
with an empty data URL doesn't produce aDataUrl
as would be expected. e.g. the following two lines... give the unexpected result:
Whereas any other non-empty data URL gives the result:
This looked like it might just require a small tweak in the code so I tried my hand at a potential fix. I'll raise a PR for it shortly in case it's helpful and of course if you agree that it's even a bug.