Problem/Motivation

Currently it's not possible to include include path in environment hostnames.

Use case could be:
I have local development environment at "local.example.com", and I can create environment with that hostname.
I have production environment at "example.com", and I can create environment with that hostname.
I have staging environment at "example.com/staging", but it's not possible add "/staging" in the hostname, because it will cause warning when validating regular expression with forward slashes (/) as pattern delimiters:

Warning: preg_match() [function.preg-match]: Unknown modifier '/' in environment_indicator_ui_validate() (line 236 of /private/var/www/vanilla/sites/all/modules/environment_indicator/environment_indicator.module).

and gives form error for invalid regular expression:
"Hostname must be a valid regular expression."

Proposed resolution

Replace forward slashes (/) with at-signs (@) in regular expression patterns. This way it would be possible to include paths in environment hostnames.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ilkkave’s picture

Issue summary: View changes
ilkkave’s picture

Here's a patch to change forward slashes (/) to at-signs (@) in regular expression patterns where needed, to allow path to be included in environment hostnames.

ilkkave’s picture

Status: Active » Needs review
e0ipso’s picture

Status: Needs review » Needs work

Instead of changing the delimiter we should probably fix the underlying bug and use preg_quote. Something like:

$regex = preg_quote($environment->regexurl, '/');
if (preg_match("/$regex/", $_SERVER['HTTP_HOST'])) {
ilkkave’s picture

Status: Needs work » Needs review
FileSize
1.28 KB

Thanks for the tip. preg_quote can be used when validating the hostname, but not when checking the environment hostname against hostname from the server, because eg. default environment wouldn't be matched in that case.

So here's a refined patch. I also added base path when checking environment hostname against current hostname, as it's needed to match path in the hostname.

  • e0ipso committed 79900c9 on 7.x-2.x authored by ilkkave
    Issue #2381171 by ilkkave: Make it possible to include path in...
e0ipso’s picture

Status: Needs review » Fixed

Merged. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.