**Background:**
See DrupalVM GitHub issue queue for how we found the error:
https://github.com/geerlingguy/drupal-vm/issues/493

**Reproducible Steps:**
1) To encounter this bug you must have a domain name with 1, 2, or 3 characters (ex. www.dev), set this up first then:
2) Install Drupal 7
3) Install the latest version of the extlink module
4) Configure the module to have only the "Open external links in a new window." checkbox checked (no other options)
5) Clear the cache and notice the symptoms below.

**Symptoms:**
1) Every single link on the page even internal Drupal links open on a new tab (incredibly frustrating)

**Bug found in extlink.js **
/^(([^\/:]+?\.)*)([^\.:]{4,})((\.[a-z]{1,4})*)(:[0-9]{1,5})?$/;

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ccjjmartin created an issue. See original summary.

ccjjmartin’s picture

Issue summary: View changes
ccjjmartin’s picture

Version: 7.x-1.10 » 7.x-1.12
ccjjmartin’s picture

Title: Extlink, DrupalVM, and PHP-FPM » New top level domains and pattern matching
Version: 7.x-1.12 » 7.x-1.18
Assigned: Unassigned » ccjjmartin
Category: Support request » Bug report
Issue summary: View changes
ccjjmartin’s picture

Version: 7.x-1.18 » 7.x-1.x-dev
Issue summary: View changes
FileSize
538 bytes

**Fix:**
Fix 1 - Changing the first 4 to a 1 fixes the actual problem of the regex breaking with a 3 character domain.
Fix 2 - As top level domains can now be any number of characters we should change the second 4 to 253 (the new standard limit)
/^(([^\/:]+?\.)*)([^\.:]{1,})((\.[a-z]{1,253})*)(:[0-9]{1,5})?$/;

**Naming:**
This fix causes the variables host and subdomain to be misrepresented, they should be renamed because host is actually top level domain (tld) and subdomain is actually domain + subdomain.

**Quick URL Testing:**
// OLD PATTERN:
var uri = "www.www.dev";
var pattern = /^(([^\/:]+?\.)*)([^\.:]{4,})((\.[a-z]{1,4})*)(:[0-9]{1,5})?$/;
console.log("full host: " + uri);
console.log("host: " + uri.replace(pattern, '$3$4'));
console.log("sub: " + uri.replace(pattern, '$1'));

// NEW PATTERN:
var uri = "www.www.dev";
var pattern = /^(([^\/:]+?\.)*)([^\.:]{1,})((\.[a-z]{1,253})*)(:[0-9]{1,5})?$/;
console.log("full host: " + uri);
console.log("host: " + uri.replace(pattern, '$3$4'));
console.log("sub: " + uri.replace(pattern, '$1'));

// OLD PATTERN OUTPUT:
VM685:4 full host: www.www.dev
VM685:5 host: www.www.dev
VM685:6 sub: www.www.dev

// NEW PATTERN OUTPUT:
VM685:10 full host: www.www.dev
VM685:11 host: dev
VM685:12 sub: www.www.

ccjjmartin’s picture

Issue summary: View changes
Status: Active » Needs review
ccjjmartin’s picture

FileSize
541 bytes

Updated patch to include support for IP addresses to address issue: https://www.drupal.org/node/2621384

  • elachlan committed d6ab635 on 7.x-1.x authored by ccjjmartin
    Issue #2679977 by ccjjmartin: New top level domains and pattern matching...

  • elachlan committed 00115f5 on 8.x-1.x authored by ccjjmartin
    Issue #2679977 by ccjjmartin: New top level domains and pattern matching...
elachlan’s picture

Status: Needs review » Fixed

Thanks for your work on this. Pushed to both 7.x and 8.x.

Status: Fixed » Closed (fixed)

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

eigentor’s picture

I am using a rather current version of Extlink (8.x-1.0), which has the new regex from the patch.
Still I experience the same issue with extlink when running a site in DrupalVM and viewing it from the Host Machine (Windows ^10) Browser.

My domain name was hsk.dev

I changed it now to be longer to evade the issue.
If I get it right, the patch should have fixed it, though?

ccjjmartin’s picture

@eigentor It looks like quite a bit of new regex logic has been added since this patch was applied (on the 8.x branch) of the project. I would recommend filling a new ticket since this one won't get much attention. The new logic adds some changes around subdomains and protocols (ex. www.hsk.dev versus web.hsk.dev and http versus https) so I would be sure to add that information to the ticket so that it will be easier to reproduce the error.