Giter Site home page Giter Site logo

ua-parser / uap-ruby Goto Github PK

View Code? Open in Web Editor NEW
252.0 8.0 44.0 219 KB

A simple, comprehensive Ruby gem for parsing user agent strings with the help of BrowserScope's UA database

License: MIT License

Ruby 100.00%
useragentparser ruby browserscope parse useragent

uap-ruby's People

Contributors

ankane avatar bcaller avatar bemurphy avatar casperisfine avatar daniel-statsig avatar fbbergamo avatar filiptepper avatar greatuserongithub avatar jnunemaker avatar luc-x41 avatar misdoro avatar nijikon avatar olleolleolle avatar opti avatar piotrze avatar rejeep avatar seandilda avatar toolmantim avatar wallin 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  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  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  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-ruby's Issues

Support for addtional custom databases

The ability to support more that one regexes database file. (regexes should be any array of filenames)

The thought here is that one file would be the "standard" from https://github.com/tobie/ua-parser/blob/master/regexes.yaml and another might contain "custom" user agents. They could be appended to the standard by sections; user_agent_parsers, os_parsers, ,device_parsers.

The files should be "loaded" in order.

Also see the request for Logstash: https://logstash.jira.com/browse/LOGSTASH-1323

1.8.7

I tried two approaches for supporting both 1.9 and 1.8.7.

  1. eval
    Converting yaml to a ruby string that's reconstructed using eval works on 1.9 and fails on 1.8.
  2. yajl
    Converting yaml to json works on 1.9 and fails the test suite on 1.8.

I'd like to use user_agent_parser in github/gollum, however 1.8 support is required. Any advice on converting yaml to a common format that can be shared between ruby versions and still pass the tests?

Remove UserAgentParser.parse

It causes unexpected performance problems (#4 #5 #13). The simpler UserAgentParser.new.parse should be less confusing.

A backwards incompatible change for v3.

MSIE 10.6 being detected as IE9

'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0'

is returning : #<UserAgentParser::UserAgent IE 9.0 (Windows 7) (Other)>

Bot detection

Hi, can you give additional functionality to detect is UA string indicates a bot or not, something like ua.is_bot? ?? Or let me know if there's something like that built in..

Unexpected result from example shown in README

The README gives the following example:

UserAgentParser.parse "Mozilla/5.0 (iPad; CPU OS 10_2_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/23.1.148956103 Mobile/14D27 Safari/600.1.4"
#=> <UserAgentParser::UserAgent Mobile Safari 10.2.1 (iOS 10.2.1) (iPad)>

however, with the current version (2.7.0), I'll a different browser:

UserAgentParser.parse "Mozilla/5.0 (iPad; CPU OS 10_2_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/23.1.148956103 Mobile/14D27 Safari/600.1.4"
#=> #<UserAgentParser::UserAgent Google 23.1.148956103 (iOS 10.2.1) (iPad)>

I've never seen a GSA/x.y.z fragment, so I'm not sure what the correct output should be ("Google 23.1.148956103" or "Safari 10.2.1").

Typo in README

I believe the command-line util example has a typo in it?

$ cat SOME-FILE-WITH-USER-AGENTS.txt | user_agent_parser --format '%f %M' | distribution

Not sure what distribution is supposed to be? Maybe grep distribution?

Git submodule should point to uap-core

The git submodule in this repo still points at https://github.com/tobie/ua-parser, but per the README:

ua-parser has moved

This project has moved to a new project space ua-parser, separating the regexes from the parsers for the different languages into their own repos:

  • uap-core : The regex file necessary to build language ports of Browserscope's user agent parser.

I figure this will probably be fixed the next time the gem is bumped to get an updated database (BTW, uap-core has updated since the last version of this gem), but I thought I'd make this issue explicit just in case. ;)

Headless Chrome is reported as Safari

This:

$ irb
jruby-9.1.8.0 :001 > require 'user_agent_parser'
 => true
jruby-9.1.8.0 :002 > ua = UserAgentParser.parse('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36')
 => #<UserAgentParser::UserAgent Safari (Linux) (Other)>
jruby-9.1.8.0 :003 > ua.to_s
 => "Safari"
jruby-9.1.8.0 :004 > ua.version
 => nil

The context is that we're using Capybara and headless Chrome to drive some testing. We record the parsed user agent in our tests and we get Safari instead of something Chrome-like.

Support for os.family?

The original ua-parser spec includes an "os.family" option. Are there any plans for including os.family in this gem?

Opinionated UA formats

Great gem, one thing I had to do immediately was to build my own display format.

user_agent = UserAgentParser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)'
=> #<UserAgentParser::UserAgent IE 9.0 (Windows Vista)>
user_agent.to_s
=> "IE 9.0"

As per above (from the docs) to_s is too brief for my liking - I actually prefer the inspect formatting.

Wondering if we should add a to_fs method or similar that maybe even has a couple of supported formats (inspired by Rails formatting of dates and times) e.g.

user_agent = UserAgentParser.parse "Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G930T Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.0 Chrome/51.0.2704.106 Mobile Safari/537.36"
=> #<UserAgentParser::UserAgent Samsung Internet 5.0 (Android 7.0) (Samsung SM-G930T)>
user_agent.to_fs
=> "Samsung Internet 5.0 (Android 7.0)"
user_agent.to_fs(:short)
=> "Samsung Internet 5.0"
user_agent.to_fs(:medium)
=> "Samsung Internet 5.0 (Android 7.0)"
user_agent.to_fs(:long)
=> "Samsung Internet 5.0 (Android 7.0) (Samsung SM-G930T)"

Open to different format suggestions.

Another option would be similar to timestamp formatting "YYYY-MM-DD HH:MM:SS Z" where we had a formatting string such as "F V (O) (D)" but that seems more confusing than helpful and doesn't deal well with optionally present information.

Release new version

I see you marked the new version in the gemspec, but it isn't pushed to rubygems yet. Anything you are waiting on that I can help with?

Android application is not properly detected

We want to use https://www.npmjs.com/package/react-native-user-agent in our app and use this gem to detect the UA, however we discovered that Android application name is not properly detected.

UserAgentParser.parse 'application-name/1.6.7.42 Dalvik/2.1.0 (Linux; U; Android 5.1.1; Android SDK built for x86 Build/LMY48X)'
=> #<UserAgentParser::UserAgent Android 5.1.1 (Android 5.1.1) (Android SDK built for x86)>

but should be
#<UserAgentParser::UserAgent application-name 1.6.7.42 (Android 5.1.1) (Android SDK built for x86)>

On iOS however everything works properly:

UserAgentParser.parse 'application-name/1.6.4.176 CFNetwork/897.15 Darwin/17.5.0 (iPhone/6s iOS/11.3)'
=> #<UserAgentParser::UserAgent application-name 1.6.4.176 (iOS 11.3) (iPhone)>

Could you fix this please?

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.