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

relative Link's href() explodes #73

Open
Vogel612 opened this issue Nov 8, 2014 · 2 comments
Open

relative Link's href() explodes #73

Vogel612 opened this issue Nov 8, 2014 · 2 comments

Comments

@Vogel612
Copy link

Vogel612 commented Nov 8, 2014

Any time one calls Link#href() on a relative link (e.g. <a href="/users/login" />) a MalformedURLException will get thrown in AbstractResource#absoluteUrl()

Code reproducing the problem:

        HtmlDocument chatLoginRootPage = agent.get("http://stackexchange.com/users/chat-login");
        Links daLinks = chatLoginRootPage.links();
        daLinks.getAll().forEach(e -> LOGGER.info(e.href()));

assumptions:

 MechanizeAgent agent = new MechanizeAgent();
 //redirect strategies for agent enabled
 private static final Logger LOGGER = java.util.Logger.getLogger(MinimalWorkingExample.class.getName());

Root cause in stack-trace (calling code omitted):

Caused by: java.net.MalformedURLException: no protocol: /users/login?returnurl=%2fusers%2fchat-login
at java.net.URL.(URL.java:586)
at java.net.URL.(URL.java:483)
at java.net.URL.(URL.java:432)
at com.gistlabs.mechanize.AbstractResource.absoluteUrl(AbstractResource.java:237)
... 8 more

@fge
Copy link

fge commented Nov 8, 2014

Well, the problem here is with HtmlDocument isn't it? Either itself or its usage. Its .href() method only contains the path, query (and fragment?) elements of the URI, not its protocol or host.

@Vogel612
Copy link
Author

Vogel612 commented Nov 8, 2014

On a sidenote, this is also happening with forms referencing relative URLs when they are submitted

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