ua-parser / uap-ref-impl Goto Github PK
View Code? Open in Web Editor NEWJavaScript reference implementation of ua-parser.
License: Other
JavaScript reference implementation of ua-parser.
License: Other
Replaces should be supported with other, high detail fields too, just family isn't enough
I'm not sure if this is the right place to ask this question since it affects multiple implementations, including this. I cross-posted to the uap-core project but sharing here just in case it is a bug with the specific implementation.
There are certain user-agents where it is not possible to derive or infer the device family, brand or model from the user-agent alone.
In our application, we want to explicitly distinguish between user-agents we recognise but we don't know of the device family (which we want to output as an empty string), and user-agents we don't recognise (fallback to the "Other" value as defined in the specification).
We've observed a difference between the uap-ref-impl
Javascript and uap-csharp
C# implementations of ua-parser.
Even though the Javascript is described as the "reference" implementation, we're not sure if this is a bug or the intention of the specification since it is vague about how to handle a replacement value that is an empty string ""
.
The specification writes,
In case that no replacement for a match is given, the first match defines the family and the model. If a *_replacement string is specified it shall overwrite or replace the match.
One could interpret "no replacement" to mean either
undefined
or null
undefined
or null
or empty stringThe regex YAML is defined as
device_parsers:
- regex: '(radiocomandroid)'
brand_replacement: ''
device_replacement: ''
model_replacement: ''
Testing with the user-agent string of radiocomandroid
The Javascript implementation outputs
{
"family": "radiocomandroid",
"brand": null,
"model": "radiocomandroid"
}
The C# implementation outputs
{
"IsSpider": false,
"Brand": "",
"Family": "",
"Model": ""
}
Side-by-side
Javascript | .NET | |
---|---|---|
Device family | "radiocomandroid" |
"" |
Device brand | null |
"" |
Device model | "radiocomandroid" |
"" |
The JavaScript implementation uses a conditional (ternary) operator which will treat an empty string ""
as false, which means it will fallback to the first match value.
Line 24 in f038cf5
The C# implementation uses a == null
condition which will use an empty string ""
as the final value.
https://github.com/ua-parser/uap-csharp/blob/master/UAParser/UAParser.cs#L523
Which of these implementations is the intent of the specification? Is an empty string considered "no replacement"?
is this the source of npm's ua-parser package?
https://www.npmjs.com/package/ua-parser
and why is the version https://github.com/ua-parser/uap-ref-impl/blob/master/package.json#L5
is lower then https://github.com/tobie/ua-parser/blob/master/package.json#L5?
@tobie: How do you expect the tests in uap-core to run? Do you prefer a download of the relevant files first or do you think including as a sub-project is more favorable?
@tobie Can you please add initial projects to "/ua-parser" for all the other languages in order to fork these "language" projects and issue PRs?
The current version on npm is v0.1.0
$ npm info uap-ref-impl | grep version:
version: '0.1.0',
The present is v0.2.0.
Can you please perform a npm publish
?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.