Skip to content

Browserslist entries that have version ranges don't match valid browsersΒ #41

@litonico

Description

@litonico

browserslist contains entries with version ranges. For instance, browserslist("ios_saf >= 9") includes the entry 'ios_saf 9.0-9.2'.
For that browserslist, browserslist-useragent matches only ios_saf 9.0. User agents with iOS Safari versions of 9.1 or 9.2 are never matched.

Steps to Repro:

const { matchesUA, resolveUserAgent } = require('browserslist-useragent')
const browserslist = require('browserslist')
ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/74.0.3729.169 Mobile/13B143 Safari/601.1.46'

console.log(resolveUserAgent(ua))
// > { family: 'iOS', version: '9.1.0' } // This is correct

console.log(matchesUA(ua, { browsers: ["ios_saf >= 9"] }))
// > false // This should be `true`

Expected behavior:
matchesUA('Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/74.0.3729.169 Mobile/13B143 Safari/601.1.46', { browsers: ["ios_saf >= 9"] }))
returns true

Actual behavior:
matchesUA('Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/74.0.3729.169 Mobile/13B143 Safari/601.1.46', { browsers: ["ios_saf >= 9"] }))
returns false

What's happening:

normalizedVersion = browserVersion.split('-')[0]

Splitting the string 'ios_saf 9.0-9.2' and taking the first array element means the only matched version is 9.0. 9.1 and 9.2 are incorrectly not matched.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions