browserslist/browserslist-useragent-regexp

regex for Safari works wrong

nikbelikov opened this issue · 3 comments

I have:

node -v && npm -v

v12.19.0
6.14.8

.browserslistrc:

last 2 safari versions

package.json:

{
  "name": "temp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "supportedBrowsers": "echo \"module.exports = $(browserslist-useragent-regexp --allowHigherVersions);\" > supportedBrowsers.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "browserslist-useragent-regexp": "^2.1.1"
  }
}

Result regex at supportedBrowsers.js:

module.exports = /(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)/;

And it works wrong for Safari 13 with userAgent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15.

Opened the console and goes:

/(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)/.test("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15")

=> false

It's WRONG!

For now, the last version is 14. Since I have last 2 safari versions at .browserslistrc, looks like the package done work not very good.

Please, help me 😔

oh, and one more thing)

last 3 firefox versions goes:
...
76 false
77 false
78 false
79 true
80 true
81 true
82 true
83 true (latest)

5 versions 🤔

@nikbelikov Hi.

Firstly, to generate most relevant regexps, you should have latest version of browserslist and caniuse data:

yarn upgrade
yarn browserslist --update-db

Secondly, you can use --verbose argument to see data received from browserslist and how it handled:

browserslist-useragent-regexp "last 2 safari versions" --verbose --allowHigherVersions       

> Browserslist

safari  13.1.0  14.0.0


> RegExps

Family:                           safari                                                                                                                                     
Versions:                         13.1.0 14.0.0                                                                                                                              
Source RegExp:                    /(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//                                                                                            
Source RegExp fixed version:      ...                                                                                                                                        
Source RegExp browsers versions:  ... - ...                                                                                                                                  
Versioned RegExp:                 /Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\//


/(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)/

Thirdly,

5 versions 🤔

To see regexp exactly for 3 versions, do not use --allowHigherVersions argument.

that's great! thank you very much!