MasoniteFramework / masonite4

Temporary Repository for a Masonite Rewrite for Masonite 4
14 stars 3 forks source link

Check/Fix back view helper #215

Closed girardinsamuel closed 2 years ago

girardinsamuel commented 2 years ago

I recreate the issue in M4 to be sure we address it in M4 : https://github.com/MasoniteFramework/masonite/issues/382

Description of the issue (correct me if wrong)

When I am calling the view including {{ back() }} with some query parameters, those are not included inside the "back generated input".

Elements to solve it

this helper use request.get_path() which do not contain query params.

We could add to request class:

# existing
def get_path(self):
    return self.environ.get("PATH_INFO")

# new
def get_path_with_query(self):
    return self.environ.get("PATH_INFO") + "?" + self.environ.get("QUERY_STRING")

And then in the helper:

# HelpersProvider.py

"back": lambda url=request.get_path_with_query(): (
    Markup(f"<input type='hidden' name='__back' value='{url}' />")
),

With this when visiting http://localhost:8000/test?key=val {{ back() }} will generate:

<input type="hidden" name="__back" value="/test?key=val">
girardinsamuel commented 2 years ago

@josephmancuso any insights on this ? I am proposing something but I might have misunderstood the problem at first...

girardinsamuel commented 2 years ago

I guess it's the correct understanding.

I was thinking: we should be consistent with the back() method of the response class. When using it with query params they should be present too. For this:

# response.py (no changes)
def back(self):
    return self.redirect(url=self.app.make("request").get_back_path())

# request.py (some changes consistent with above)
def get_back_path(self):
    return self.input("__back") or self.get_path_with_query()
girardinsamuel commented 2 years ago

Summary of all changes can be found in the PR #216