Problem/Motivation

When invites are generated they sometimes contain characters that break routing, for example I had one that generated a "/" in it which through the following error.

Parameter "invite" for route "invite.invite_accept_accept" must match "[^/]++" ("jE/2uqprEk" given) to generate a corresponding URL.

Proposed resolution

Change the invite codes to be url safe instead of using a password generator.

Issue fork invite-3532841

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

josh.fabean created an issue. See original summary.

josh.fabean’s picture

Created method to generate URL safe codes.

  protected static function generateUrlSafeCode(int $length): string {
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    $code = '';

    for ($i = 0; $i < $length; $i++) {
      $code .= $chars[random_int(0, strlen($chars) - 1)];
    }

    return $code;
  }
renatog’s picture

Maybe the solution on #3 works, however just as a curiosity, isn’t possible implementing this with Regex?

renatog’s picture

NVM, please ignore my question above. Regex is for matching, not creating

So seems good, thanks

renatog’s picture

Status: Active » Needs review