Skip to content

Commit

Permalink
Update / rework spec
Browse files Browse the repository at this point in the history
UA spec I feel has major issues, especially that respecting it makes
it impossible for tests to pass, leading to implementations having to
copy one another or do their own random hack (as the C# implementation
does).

There are two major issues in the 0.2 spec:

Replacement fields templating
-----------------------------

It states that the OS fields have individual replacements, that is
match `$1` is only used in `os_replacement`, match `$2` is only used
in `os_v1_replacement`, etc...

However there are multiple test suites which use `$1` in
`os_v1_replacement` (macos, win, Box.Windows), and macOS also uses
`$2` and `$3` in shifted position.

The reference implementation handle this by just making the OS fields
into "full" templates (that is all groups are available to all
replacement fields). The C# implementation instead tries to mess
around with different orders for v1 and v2 based on what it finds
there.

Obviously it makes sense to standardise the behaviour of the standard
implementation instead of the hack of the C# lib.

But for uniformity and to allow for less redundant explanations, I
think it also makes sense to make the `user_agent_parsers` fields into
"full" templates (that is, all groups are available) even if no parser
currently uses that. In fact that's how the Python and Go
implementations behave already.

Side-note: far from extending the spec, the reference implementation
doesn't even implement it in full as it only supports replacing `$1`
in `family_replacement`, it has no support for templating at all in
`v1_replacement`, `v2_replacement`, or `v3_replacement`.

`Device#model_replacement` can't be required
--------------------------------------------

Despite what the spec currently says, one of the user agents
(`Opera/9.80 (BlackBerry; Opera Mini/7.0.31437/28.3030; U; en)`) has
no capturing group and no `model_replacement`, so it's not possible to
parse it per-expectation if `model_replacement` is required.

As such, only `Device#device_replacement` should be required.
  • Loading branch information
masklinn committed May 24, 2022
1 parent 09e9ccc commit 89316dc
Showing 1 changed file with 235 additions and 135 deletions.
Loading

0 comments on commit 89316dc

Please sign in to comment.