0

Hi I am confused by this discrepancy of URI/URL parsing between C#, Java and PHP. For example, I have string url = "http://*.bar.com"

In C#: new Uri(url) will throw a System.UriFormatException error,

But in Java new URL(url) will pass, same as in PHP using parse_url(url)(with $url = "http://*.bar.com")

Is that the C# is wrong or Java & PHP are wrong?

Update: I've consulted this page,even I put string url = "http://%2A.bar.com", the new Uri(url) would fail. But interestingly, string url = "http://foo.domain.com/something/*" will pass new Uri()

Community
  • 1
  • 1
Allen Lin
  • 1,179
  • 4
  • 13
  • 23
  • 1
    possible duplicate of [Allowing asterisk in URL](http://stackoverflow.com/questions/4567215/allowing-asterisk-in-url) – eric.m Aug 21 '15 at 16:10
  • Thanks @Emd4600 I should've mentioned that I looked at that page. – Allen Lin Aug 21 '15 at 16:13
  • Probably `http://%2A.bar.com` doesn't work because that's still an asterisk, and it's use is reserved. Isn't there any alternative you could use instead of an asterisk? – eric.m Aug 21 '15 at 16:18
  • Even if not duplicated, it might be [too open ended/subjective](http://stackoverflow.com/help/dont-ask)?. Even if ! and * should not be used in an HTTP Url (although could be used in specific protocols). Would it really worth to check for all the applicable protocols if there are invalid characters? + Are we the language developers to answer those questions? – Javier Aug 21 '15 at 16:21
  • @Emd4600 we are trying to allow wildcard in user input URL. Currently, this asterisk is implemented in our other version (Java and PHP) so it's expensive to change the wildcard from asterisk to other. – Allen Lin Aug 21 '15 at 16:27
  • @Javier I just want to know if there is official standard saying if asterisk is not allowed in URI/URL. Looking at the W3 stuff, [it is RECOMMENDED not to use asterisk in URI](http://www.w3.org/Addressing/URL/4_URI_Recommentations.html). But interestingly, it's not mentioned in [URL doc](http://www.w3.org/Addressing/URL/4_Recommentations.html) – Allen Lin Aug 21 '15 at 16:33
  • @AllenLin In that question you told you read, the [highest voted answer](http://stackoverflow.com/a/4567374/1117429) cites `**Other reserved characters** The asterisk ("*", ASCII 2A hex) and exclamation mark ("!" , ASCII 21 hex) are reserved for use as having special signifiance within specific schemes.`. I interpreted scheme as protocol (as some exotic not IETF protocol, although I might be wrong) – Javier Aug 21 '15 at 16:55
  • @Javier yes. I don't think I fully agree with the answer from that page as I found that although the asterisk does not work in subdomain, it works in path `string url = "http://domain.com/*` will pass `new Uri(url)`. This mean asterisk is not fully unsupported in C#'s `Uri()` – Allen Lin Aug 21 '15 at 17:29

0 Answers0