Mocking a web request with the excellent WebMock library lead to the following error:
1 2 |
|
Symptoms
This error occured whenever a domain contained _
, e.g. an underscore character.
Solution
I was dealing with a mock URL anyway, I was able to replace the underscore with a hyphen -
.
At the end of this rubyforums discussion you can find a relatively simple solution which solves this problem for cases where you have no control over the domain name:
1 2 |
|
Discussion
The aforementioned discussion has some interesting insights, on which I will give a brief summary here:
RFC 1738, section 3.1. explains the host scheme:
1 2 |
|
In short, URI won’t parse domain names with underscores. Those are officially invalid, even though they are used sometimes. Some people don’t have the luxury to just change the URI since some domain names contain an underscore and need to be accessed.
If you have no control over the domain, you can either
- use a modified URI parser (see “Solution” section), or
- monkeypatch the URI module (looks rather dirty to me).