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

Creating a direct link after a substitution link does not result in match #18

Open
robdoesstuff opened this issue Dec 3, 2020 · 4 comments
Labels
question Further information is requested

Comments

@robdoesstuff
Copy link

If I make a link like go/logs with a %s to capture the rest so that a general go/logs/mything translates to a URL with mything substituted in, then I create go/logs-otherthing, going to go/logs/otherthing still matches the first logs go link. It should have the opposite sort where the more specific matches come first and the general are the defaults if there is no other match. This allows me to setup a catch all link then overrides with more specific urls, such as in the case of navigating to customized dashboards, logs, etc.

@LaikaN57
Copy link
Member

Hello @robdoesstuff 👋 Can you clarify your post. Here is the config and result as I understood it.

This config...

Shortcut URL Secondary URL
go/logs logs.com/all_logs logs.com/%s
go/logs-otherthing example.com N/A

Would result in this...

Shortcut > Destination
go/logs > logs.com/all_logs
go/logs/mything > logs.com/mything
go/logs/otherthing > logs.com/otherthing
go/logs-otherthing > example.com

@LaikaN57 LaikaN57 added the question Further information is requested label Jun 15, 2022
@robdoesstuff
Copy link
Author

It's been a while but I do not believe that's the result I got. It seems like we have some hyphen-slash substitution happening and any go/logs/anything or go/logs-anything will match the shorter go/logs rule and not the go/logs-otherthing rule. Perhaps this isn't a problem anymore, I'm not sure. I can see if I can retest this in our deployment.

@LaikaN57
Copy link
Member

ok and just to make sure, what release are you on?

@LaikaN57
Copy link
Member

Here is the relevant code path in main right now:

  • Router:

    gogo/src/app.py

    Lines 55 to 58 in 4eff6d4

    app.add_url_rule(
    '/<regex(".+"):name>',
    view_func=gogo.ShortcutRedirectView.as_view("shortcut_redirect"),
    )
  • View:

    gogo/src/gogo.py

    Lines 140 to 171 in 4eff6d4

    def get(self, name):
    secondary_arg = None
    if "/" in name:
    name, secondary_arg = name.split("/", 1)
    if name in RESERVED_NAMES:
    flask.abort(404)
    shortcut = Shortcut.query.filter(Shortcut.name == name).first()
    if shortcut:
    # TODO: Move the write to a task queue.
    # SUBTODO: Figure out what the above TODO means.
    # TODO: what if more than 1
    shortcut.hits += 1
    db.session.add(shortcut)
    db.session.commit()
    if (
    secondary_arg
    and shortcut.secondary_url
    and "%s" in shortcut.secondary_url
    ):
    response = flask.make_response(
    flask.redirect(
    str(shortcut.secondary_url).replace("%s", secondary_arg)
    )
    )
    else:
    response = flask.make_response(
    flask.redirect(str(shortcut.url), code=301)
    )
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    return response

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

No branches or pull requests

2 participants