**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})?$/;
Comment | File | Size | Author |
---|---|---|---|
#7 | extlink-regex-2679977-7-D7.diff | 541 bytes | ccjjmartin |
|
Comments
Comment #2
ccjjmartin CreditAttribution: ccjjmartin commentedComment #3
ccjjmartin CreditAttribution: ccjjmartin commentedComment #4
ccjjmartin CreditAttribution: ccjjmartin as a volunteer commentedComment #5
ccjjmartin CreditAttribution: ccjjmartin as a volunteer commented**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.
Comment #6
ccjjmartin CreditAttribution: ccjjmartin as a volunteer commentedComment #7
ccjjmartin CreditAttribution: ccjjmartin as a volunteer commentedUpdated patch to include support for IP addresses to address issue: https://www.drupal.org/node/2621384
Comment #10
elachlan CreditAttribution: elachlan commentedThanks for your work on this. Pushed to both 7.x and 8.x.
Comment #12
eigentor CreditAttribution: eigentor commentedI 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?
Comment #13
ccjjmartin CreditAttribution: ccjjmartin as a volunteer commented@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.