Make WordPress Core

#55297 closed defect (bug) (fixed)

The $is_edge global returns false.

Reported by: costdev's profile costdev Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.0 Priority: normal
Severity: normal Version: 6.0
Component: General Keywords: good-first-bug has-testing-info has-patch commit
Focuses: Cc:

Description

$is_edge is true when "Edge" is detected.

However, user agents for Edge have changed such that "Edg" is the only consistent substring across devices. As a result, $is_edge returns false.

Changing the substring to "Edg" in src/wp-includes/vars.php:68 seems to fix this.

Steps to reproduce and test the solution:

  1. Add this to functions.php:
global $is_edge;
die( var_export( $is_edge, true ) );
  1. Load any page. false should be displayed.
  2. Change "Edge" to "Edg" in src/wp-includes/vars.php:68.
  3. Reload the page. true should now be displayed.

Reference: Microsoft Docs - Identifiers for Microsoft Edge on various platforms

Attachments (1)

55297-03032022.diff (652 bytes) - added by abdullahramzan 22 months ago.
Fix for 55297

Download all attachments as: .zip

Change History (12)

@abdullahramzan
22 months ago

Fix for 55297

#1 @abdullahramzan
22 months ago

  • Keywords has-patch added; needs-patch needs-testing removed

Hi @costdev,

Thanks for submitting the ticket with a useful guide & test information. I have created a patch & tested it locally. It looks good to me. Webpage returning true when opening in Microsoft Edge.

Best Regards,

#2 @costdev
22 months ago

  • Keywords needs-testing added

Thanks for the patch @abdullahramzan!

I'm confident that this solution works, but let's add needs-testing so that the original issue is reproduced and the solution is tested by someone other than myself as the reporter and yourself as the patcher.

I'll post in the core-test Slack channel to help move this ticket along more quickly.

This ticket was mentioned in Slack in #core-test by costdev. View the logs.


22 months ago

#4 @mukesh27
22 months ago

Hi there!

The patch looks good to me.

The latest user agents for Edge - https://www.whatismybrowser.com/guides/the-latest-user-agent/edge

#5 @costdev
22 months ago

  • Keywords commit added; needs-testing removed

Thanks @mukesh27!

Marking for commit consideration.

#6 @peterwilsoncc
22 months ago

This code may need to be more specific.

Via a list of user agents chosen at random, I discovered there is an old version of Ubuntu called Edgy Eft.

It's an edge case (pun intended) but the change should probably account for the version of Firefox that include the OS name.

Maybe check for Edg/, EdgiOS/ and EdgA/. The annoyance here is that you'll probably need to include the previous check for edge for older versions.

#7 @peterwilsoncc
22 months ago

  • Keywords commit removed

#8 @costdev
22 months ago

Edgy Eft uses Ubuntu-edgy:

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20060601 Firefox/2.0.0.1 (Ubuntu-edgy)

Since strpos() is case sensitive, it returns false: 3v4l

#9 @Boniu91
22 months ago

Test Report

Env

  • WordPress 5.9 with patch applied
  • Edge 98.0.1108.62
  • Theme: Twenty Twenty One

Steps to test

  1. Added the following code to functions.php:
    global $is_edge;
    die( var_export( $is_edge, true ) );
    
  2. Visited the page using Edge
  3. true is displayed

#10 @peterwilsoncc
21 months ago

  • Keywords commit added

Thanks @costdev and @Boniu91

Since strpos() is case sensitive, it returns false

Yes, indeed, excellent point.

#11 @peterwilsoncc
21 months ago

  • Owner set to peterwilsoncc
  • Resolution set to fixed
  • Status changed from new to closed

In 52825:

General: Improve MS Edge user-agent sniff.

Update the $is_edge global to be true if the browser's user-agent contains Edg rather than Edge. Microsoft have dropped an E from the UA string.

Refer to Microsoft's documentation on detecting edge.

Props costdev, abdullahramzan, mukesh27, Boniu91.
Fixes #55297.

Note: See TracTickets for help on using tickets.