Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

won't parse domains #115

Closed
ralyodio opened this issue Sep 7, 2013 · 6 comments
Closed

won't parse domains #115

ralyodio opened this issue Sep 7, 2013 · 6 comments

Comments

@ralyodio
Copy link

ralyodio commented Sep 7, 2013

search (google.com)

this string fails.

@rodneyrehm
Copy link
Member

I'm sorry, but I don't understand the issue. are you calling .search("google.com")? Have you looked at what .search() does?

URI('/').search('google.com').toString() === "/?google.com";

@ralyodio
Copy link
Author

ralyodio commented Sep 7, 2013

No the literal string 'google.com'. Is not parsed. Ignore the search that was just the context of my string.

-- Anthony

On Sep 7, 2013, at 1:32 AM, Rodney Rehm notifications@github.com wrote:

I'm sorry, but I don't understand the issue. are you calling .search("google.com")? Have you looked at what .search() does?

URI('/').search('google.com').toString() === "/?google.com";

Reply to this email directly or view it on GitHub.

@rodneyrehm
Copy link
Member

I can see your problem now. In order to have an authority parsed as such, you need to add the protocol separator // otherwise the string is treated as a relative path.

URI('google.com').path() === 'google.com';
URI('//google.com').domain() === 'google.com';

This is not a bug. This is ambiguity at its best… :(

@ralyodio
Copy link
Author

ralyodio commented Sep 8, 2013

I was actually trying this code with 'google.com' and it failed to recognize a url.

var source = "Hello www.example.com,\n"
    + "google.com is a search engine, like http://www.bing.com\n"
    + "http://exämple.org/foo.html?baz=la#bumm is an IDN URL,\n"
    + "http://123.123.123.123/foo.html is IPv4 and "
    + "http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n"
    + "links can also be in parens (http://example.org) "
    + "or quotes »http://example.org«.";

var result = URI.withinString(source, function(url) {
    return "<a>" + url + "</a>";
});

/* result is:
Hello <a>www.example.com</a>,
<a>http://google.com</a> is a search engine, like <a>http://www.bing.com</a>
<a>http://exämple.org/foo.html?baz=la#bumm</a> is an IDN URL,
<a>http://123.123.123.123/foo.html</a> is IPv4 and <a>http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html</a> is IPv6.
links can also be in parens (<a>http://example.org</a>) or quotes »<a>http://example.org</a>«.
*/

@rodneyrehm rodneyrehm reopened this Sep 8, 2013
@rodneyrehm
Copy link
Member

Ok, so you're talking about URI.withinString. Please add this (vital) piece of information in the issue description the next time you open an issue somewhere…

The regular expression used to extract URIs from text expects a URI to either begin with a protocol (e.g. http://) or with the subdomain www. Feel free to modify the expression, located at URI.find_uri_expression, to your liking. for reference, URI.js is using the "gruber revised" from here.

@rodneyrehm
Copy link
Member

The issue is resolved in v1.12.0 see the docs for an enhanced API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants