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

It returns null when the url is an empty string #37

Closed
hernangm opened this issue Nov 28, 2014 · 4 comments
Closed

It returns null when the url is an empty string #37

hernangm opened this issue Nov 28, 2014 · 4 comments
Labels

Comments

@hernangm
Copy link

An empty string is a valid url resolvable from a route. However when finalUrl is an empty string, it returns null and it should return the empty string.

@Daniel15
Copy link
Owner

Thanks for reporting this! Sorry for the delay in replying. I'll look into this in the new year. In the meantime, feel free to send a pull request if you resolve the issue :)

@Daniel15
Copy link
Owner

Just getting back into things now. Is an empty string really a valid URL? Wouldn't it be / for the root?

@hernangm
Copy link
Author

Hi Daniel,

I have the following controller

public class HomeController : Controller
{
    [HttpGet, Route("")]
    public virtual ActionResult Index()
    {
        return View();
    }
}

but when I call

Router.action("Home", "Index") in my js files I get some exception, although the route does exist in the list of registered routes as

"{"route":{"url":"","defaults":{"controller":"Home","action":"Index"},"constraints":{},"optional":[]},"_params":[],"_parsedConstraints":{}}"

I did some debugging and the problem seems to be here:

        // Try to merge all URL parameters
        // If null, this means a required parameters was not specified.
        finalUrl = this._merge(finalValues, processedParams);
        if (!finalUrl) {
            return null;
        }

When finalUrl is "", that is evaluated by !finalUrl as a truish value, returning null. I think it could be fixed if finalUrl is checked against null directly.

@Daniel15
Copy link
Owner

Good catch, thanks! I'll try to take a look soon.

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

No branches or pull requests

2 participants