GithubHelp home page GithubHelp logo

uap-ref-impl's People

Contributors

commenthol avatar elsigh avatar ironholds avatar theikkila avatar tobie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uap-ref-impl's Issues

Running Tests with ref parser

@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?

Handling of empty string replacement values differs between implementations

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.

Background

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 string

Repro

The 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" ""

Question

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.

family: (deviceRep ? replaceMatches(deviceRep, m) : m[1]) || 'Other',

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"?

uap-ref-impl needs update on npm

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.