Incosistent use of error feedback in consume scheme
THEvang opened this issue · 2 comments
Consume scheme uses both exceptions and nullopts to signal an erroneous scheme and I think we should stick to one of them. I would prefer nullopt.
I also don't think it throws if the scheme is empty.
If pos is to be zero, then it must never increase. That happens for instance if we give an empty input. However, then pos == input.size() because both pos and input size is zero, thereby triggering the first if branch returning nullopts.
If we give an non-empty string with an empty scheme such as "://example.com", then the scheme is empty, but the scheme empty exception is not thrown because inputs[pos] == : since pos is never increased because : is not a scheme character.
The other way is if we give a weird scheme like ////: because / is not an alphanumeric character. Then, the exception is thrown, not because the scheme is empty, but because it is invalid.
Line 46 in 22a89c4
The use of both exceptions and nullopts is by design. The intent is that it should return a nullopt if the given string doesn't contain any scheme (in which case it's a relative URI reference, not an absolute URI), and that it should throw if there appears to be a scheme but it's empty.
It looks to me like it will throw on a string like ://example.com
. Did you test it?
You are correct. I misread !=
as ==
in the first if branch.