Turn server fixes (malformed uris and FF NS_ERROR_UNEXPECTED)

These commits contain 2 changes (fixes) regarding UA construction with turn servers.
For details have a look at the commit messages for each. If you want me to squash let me know.
(And of course if I made a mistake or you want me to change something or if I should provide more information).

Cheers
Is this change necessary?  If it is, can the `length` variable be removed altogether?  This comment won't block the pull request, but I do want to make sure I'm not missing something.