Codebase list golang-github-mssola-user-agent / 31f8992
Import upstream version 0.5.3 Debian Janitor 2 years ago
16 changed file(s) with 500 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
0 ---
1 name: Custom issue template
2 about: General issues, both bugs and features.
3 title: ''
4 labels: ''
5 assignees: mssola
6 ---
7
8 ### Description
9
10 Check out the [contribution guidelines](../CONTRIBUTING.md) file for some considerations before submitting a new issue.
11
12 ### Steps to reproduce
13
14 1. First I did this...
15 2. Then that...
16 3. And this happened!
17
18 - **Expected behavior**: I expected this to happen!
19 - **Actual behavior**: But this happened...
20
21 ### user_agent version
22
23 With a git commit SHA if possible.
24
25 ### Go version and interpreter
26
27 ```bash
28 $ go version
29 ```
30
31 ### Operating system
32
33 The operating system and the exact version you are using. If you are using Linux, it may be useful to know which distribution you are using and what did you do in order to install go.
0 Provide a general description of the changes in your pull request. If this pull request fixes a known issue, please tag it as well (e.g.: `Fixes #1`).
1
2 Before submitting a PR make sure the following things have been done (and denote this by checking the relevant checkboxes):
3
4 - [ ] The commits are consistent with the [contribution guidelines](../CONTRIBUTING.md).
5 - [ ] You've added tests (if possible) to cover your change(s).
6 - [ ] All tests and style checkers are passing (`make ci`).
7 - [ ] You've updated the [changelog](../CHANGELOG.md).
8 - [ ] You've updated the [readme](../README.md) (if relevant).
9
10 Thanks for contributing to user_agent!
00 language: go
1
2 git:
3 depth: false
4
5 arch:
6 - amd64
7 - ppc64le
8
19 go:
210 - 1.4.x
311 - 1.5.x
513 - 1.7.x
614 - 1.8.x
715 - 1.9.x
16 - 1.10.x
17 - 1.11.x
18 - 1.12.x
19 - 1.13.x
20 - 1.14.x
821 - 1.x
922 - tip
1023 matrix:
1124 allow_failures:
1225 - go: tip
26 exclude:
27 - go: 1.4.x
28 arch: ppc64le
29
30 before_install:
31 - chmod +x ./ci/install.sh && ./ci/install.sh
32
33 script:
34 - make ci
00 # Changelog
1
2 ## Not yet released
3
4 ## 0.5.3
5
6 - Fix detection of Firefox on iPad. See [42e4a8f39125](https://github.com/mssola/user_agent/commit/42e4a8f39125a6680fb5367a4602963f1351e069).
7 - Fix detection of Linux ARM-based Android. See [3b0e113c8047](https://github.com/mssola/user_agent/commit/3b0e113c804708c01de00c27aae07d2acfee40d8).
8 - Add detection of Chromium Edge on Windows. See [ea81f1e9d61c](https://github.com/mssola/user_agent/commit/ea81f1e9d61c094df4156690a8f4d5481b0d6c4a).
9 - Add detection of OkHttp. See [6b33e248e796](https://github.com/mssola/user_agent/commit/6b33e248e7969cf3e76128a34d33be88d4eb0dc8).
10
11 ## 0.5.2
12
13 - Detect Electron. See [commit](https://github.com/mssola/user_agent/commit/1a36963d74c0efca7de80dc7518a0958c66b3c4f).
14 - Add support for both http and https site urls. See [commit](https://github.com/mssola/user_agent/commit/d78bf2c5886a0ab7e1cf90b68c808fe3e3ab6f8c).
15 - Add more support for BingBot. See [commit](https://github.com/mssola/user_agent/commit/c6402a7b8aefdc4acfbf1e7f3b43eac0b266e49e).
16 - Add a test case for Firefox focus on iOS. See [commit](https://github.com/mssola/user_agent/commit/a1e9c19d5a6887a17cef1d249118ccbd45cf4c0b).
17 - Detect iMessage-Preview. See [commit](https://github.com/mssola/user_agent/commit/e8f5e19ded9711ee1f4b43218b9d57d00ef5c26a).
118
219 ## 0.5.1
320
4 - 00a868fa17e7 add Firefox for iOS
5 - 8c16c37f4e07 Add go.mod
6 - 7e313fc62553 Use CodeLingo to Address Further Issues
7 - 95b0c164394f Fix function comments based on best practices from Effective Go
8 - 1df9e04ee4f5 test: mobile Yandex Browser
9 - 6eb76c60b5e8 Add Yandex browser
10 - 8b3999083770 Updating license notice
11 - 82f141dea4a8 Detect Chrome for iOS correctly
12 - 5723c361ed97 Facebook App Handling
13 - 57c32981bd5f Add a new google bot user agent format
21 - add Firefox for iOS. See [commit](https://github.com/mssola/user_agent/commit/00a868fa17e7).
22 - Add go.mod. See [commit](https://github.com/mssola/user_agent/commit/8c16c37f4e07).
23 - Use CodeLingo to Address Further Issues. See [commit](https://github.com/mssola/user_agent/commit/7e313fc62553).
24 - Fix function comments based on best practices from Effective Go. See [commit](https://github.com/mssola/user_agent/commit/95b0c164394f).
25 - test: mobile Yandex Browser. See [commit](https://github.com/mssola/user_agent/commit/1df9e04ee4f5).
26 - Add Yandex browser. See [commit](https://github.com/mssola/user_agent/commit/6eb76c60b5e8).
27 - Updating license notice. See [commit](https://github.com/mssola/user_agent/commit/8b3999083770).
28 - Detect Chrome for iOS correctly. See [commit](https://github.com/mssola/user_agent/commit/82f141dea4a8).
29 - Facebook App Handling. See [commit](https://github.com/mssola/user_agent/commit/5723c361ed97).
30 - Add a new google bot user agent format. See [commit](https://github.com/mssola/user_agent/commit/57c32981bd5f).
1431
1532 ## 0.5.0
1633
1734 ### Newly supported and improvements
1835
19 - f659b9863849 Added support for Microsoft Edge
20 - 783ec61292ae Precompile regular expressions
21 - 78413629666f Added support for Dalvik user agent parsing
22 - 0319fcf00bfd Improved bot support (also e25e612b37a4)
23 - 6e7843e05771 Add Chromium support and Ubuntu specific tests
24 - 3335cae017e7 Add OSInfo function to user agent (also 7286ca6abc28)
25 - 6fe362d7cd64 Detect updated UA for Googlebot
26 - 1438bfba89d7 Adds the Adsense bot (mobile)
36 - Added support for Microsoft Edge. See [commit](https://github.com/mssola/user_agent/commit/f659b9863849).
37 - Precompile regular expressions. See [commit](https://github.com/mssola/user_agent/commit/783ec61292ae).
38 - Added support for Dalvik user agent parsing. See [commit](https://github.com/mssola/user_agent/commit/78413629666f).
39 - Improved bot support (also e25e612b37a4). See [commit](https://github.com/mssola/user_agent/commit/0319fcf00bfd).
40 - Add Chromium support and Ubuntu specific tests. See [commit](https://github.com/mssola/user_agent/commit/6e7843e05771).
41 - Add OSInfo function to user agent (also 7286ca6abc28). See [commit](https://github.com/mssola/user_agent/commit/3335cae017e7).
42 - Detect updated UA for Googlebot. See [commit](https://github.com/mssola/user_agent/commit/6fe362d7cd64).
43 - Adds the Adsense bot (mobile). See [commit](https://github.com/mssola/user_agent/commit/1438bfba89d7).
2744
2845 ### Fixes
2946
30 - 8d86c2cf88bf Fixed bug when extracting windows 10
31 - 9d00ff9e4202 Fixed bug on mobile Firefox browsers running on Android OS versions that report their version number inline.
47 - Fixed bug when extracting windows 10. See [commit](https://github.com/mssola/user_agent/commit/8d86c2cf88bf).
48 - Fixed bug on mobile Firefox browsers running on Android OS versions that report their version number inline.. See [commit](https://github.com/mssola/user_agent/commit/9d00ff9e4202).
3249
3350 ### Other
3451
35 63395b193f8812526305bec75ea7117262a124aa Improved testing infrastructure (also 63395b193f8812526305bec75ea7117262a124aa)
52 - Improved testing infrastructure. See [commit](https://github.com/mssola/user_agent/commit/63395b193f8812526305bec75ea7117262a124aa).
3653
3754 ## Older releases
3855
0 # Contributing to user_agent
1
2 ## Check that your changes do not break anything
3
4 You can safely run the `ci` target locally:
5
6 ```
7 $ make ci
8 ```
9
10 This will run all the make targets that will also be run on the CI, which are
11 described below.
12
13 ### Running tests
14
15 Call the `test` make target:
16
17 ```bash
18 $ make test
19 ```
20
21 ### Checking the style
22
23 This project uses some standard tools in order to check the Go style. You can
24 run them by calling the `validate-go` make target:
25
26 ```bash
27 $ make validate-go
28 ```
29
30 This target is included inside of the `validate` one.
31
32 ### Git validation
33
34 In order to ensure that the git log is as maintainable as possible, the
35 [git-validation](https://github.com/vbatts/git-validation) tool is used. You can
36 install this tool by running:
37
38 ```bash
39 $ go get -u github.com/vbatts/git-validation
40 ```
41
42 If you already have this tool installed, then simply perform:
43
44 ```bash
45 $ make git-validation
46 ```
47
48 One of the things you will notice is that it will check that the commits have a
49 sign off, that is, that you have used the `-s` flag when calling `git
50 commit`. This is a lightweight way for contributors to certify that they wrote
51 or otherwise have the right to submit the code they are contributing into this
52 project.
53
54 This target is included inside of the `validate` one.
55
56 ## Issue reporting
57
58 I'm using [Github](https://github.com/mssola/user_agent) in order to host the
59 code. Thus, in order to report issues you can do it on its [issue
60 tracker](https://github.com/mssola/user_agent/issues). A couple of notes on
61 reports:
62
63 - Check that the issue has not already been reported or fixed in `master`.
64 - Try to be concise and precise in your description of the problem.
65 - Provide a step by step guide on how to reproduce this problem.
66 - Provide the version you are using (the commit SHA, if possible).
67
68 ## Pull requests
69
70 - Write a [good commit message](https://chris.beams.io/posts/git-commit/).
71 - Make sure that tests are passing on your local machine (it will also be
72 checked by the CI system whenever you submit the pull request).
73 - Update the [changelog](./CHANGELOG.md).
74 - Try to use the same coding conventions as used in this project.
75 - Open a pull request with *only* one subject and a clear title and
76 description. Refrain from submitting pull requests with tons of different
77 unrelated commits.
0 Copyright (c) 2012-2019 Miquel Sabaté Solà
0 Copyright (c) 2012-2021 Miquel Sabaté Solà
11
22 Permission is hereby granted, free of charge, to any person obtaining
33 a copy of this software and associated documentation files (the
0 GO ?= go
1 GO_SRC = $(shell find . -name \*.go)
2
3 .DEFAULT: build
4 build: $(GO_SRC)
5 @$(GO) build
6
7 #
8 # Unit & integration tests.
9 #
10
11 .PHONY: test
12 test:
13 @$(GO) test
14
15 .PHONY: bench
16 bench:
17 @$(GO) test -bench=.
18
19 #
20 # Validation tools.
21 #
22
23 EPOCH_COMMIT ?= 2046da2a89bd
24 .PHONY: git-validation
25 git-validation:
26 ifeq (, $(shell which git-validation 2> /dev/null))
27 @echo "You don't have 'git-validation' installed, consider installing it (see the CONTRIBUTING.md file)."
28 else
29 @git-validation -q -range $(EPOCH_COMMIT)..HEAD -travis-pr-only=false
30 endif
31
32 .PHONY: validate-go
33 validate-go:
34 @which gofmt >/dev/null 2>/dev/null || (echo "ERROR: gofmt not found." && false)
35 @test -z "$$(gofmt -s -l . | grep -vE '^vendor/' | tee /dev/stderr)"
36 @chmod +x ci/lint.sh
37 @./ci/lint.sh
38 # Go 1.4.x does not have go vet, so there is no point on trying.
39 ifneq ("$(TRAVIS_GO_VERSION)","1.4.x")
40 @go doc cmd/vet >/dev/null 2>/dev/null || (echo "ERROR: go vet not found." && false)
41 @test -z "$$(go vet . | grep -v vendor | tee /dev/stderr)"
42 endif
43
44 .PHONY: validate
45 validate: git-validation validate-go
46
47 #
48 # Travis-CI
49 #
50
51 .PHONY: ci
52 ci: build validate test
00
1 # UserAgent [![Build Status](https://travis-ci.org/mssola/user_agent.png?branch=master)](https://travis-ci.org/mssola/user_agent) [![GoDoc](https://godoc.org/github.com/mssola/user_agent?status.png)](http://godoc.org/github.com/mssola/user_agent)
1 <p align="center">
2 <a href="https://travis-ci.org/mssola/user_agent" title="Travis CI status for the master branch"><img src="https://travis-ci.org/mssola/user_agent.svg?branch=master" alt="Build Status for master branch" /></a>
3 <a href="http://godoc.org/github.com/mssola/user_agent" title="godoc.org page"><img src="https://godoc.org/github.com/mssola/user_agent?status.png" alt="godoc.org page" /></a>
4 <a href="https://en.wikipedia.org/wiki/MIT_License" rel="nofollow"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-blue.svg" style="max-width:100%;"></a>
5 </p>
26
7 ---
38
4 UserAgent is a Go library that parses HTTP User Agents.
9 UserAgent is a Go library that parses HTTP User Agents. As an example:
510
6 ## Usage
7
8 ~~~ go
11 ```go
912 package main
1013
1114 import (
4548 fmt.Printf("%v\n", name) // => Googlebot
4649 fmt.Printf("%v\n", version) // => 2.1
4750 }
48 ~~~
51 ```
4952
50 Copyright &copy; 2012-2019 Miquel Sabaté Solà, released under the MIT License.
53 If you want to read the full API documentation simply check
54 [godoc](http://godoc.org/github.com/mssola/user_agent).
55
56 ## Installation
57
58 ```
59 go get -u github.com/mssola/user_agent
60 ```
61
62 ## Contributing
63
64 Do you want to contribute with code, or to report an issue you are facing? Read
65 the [CONTRIBUTING.md](./CONTRIBUTING.md) file.
66
67 ## [Changelog](https://pbs.twimg.com/media/DJDYCcLXcAA_eIo?format=jpg&name=small)
68
69 Read the [CHANGELOG.md](./CHANGELOG.md) file.
70
71 ## License
72
73 ```
74 Copyright (c) 2012-2021 Miquel Sabaté Solà
75
76 Permission is hereby granted, free of charge, to any person obtaining
77 a copy of this software and associated documentation files (the
78 "Software"), to deal in the Software without restriction, including
79 without limitation the rights to use, copy, modify, merge, publish,
80 distribute, sublicense, and/or sell copies of the Software, and to
81 permit persons to whom the Software is furnished to do so, subject to
82 the following conditions:
83
84 The above copyright notice and this permission notice shall be
85 included in all copies or substantial portions of the Software.
86
87 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
88 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
89 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
90 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
91 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
92 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
93 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
94 ```
0 // Copyright (C) 2012-2019 Miquel Sabaté Solà <mikisabate@gmail.com>
0 // Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com>
11 // This file is licensed under the MIT license.
22 // See the LICENSE file.
33
4444 expected: "Mozilla:5.0 Browser:bingbot-2.0 Bot:true Mobile:false",
4545 },
4646 {
47 title: "BingBotSmartphone(iPhone)",
48 ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
49 expected: "Mozilla:5.0 Browser:bingbot-2.0 Bot:true Mobile:true",
50 },
51 {
52 title: "BingBotSmartphone(Android)",
53 ua: "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 Edg/80.0.345.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
54 expected: "Mozilla:5.0 Browser:bingbot-2.0 Bot:true Mobile:true",
55 },
56 {
57 title: "BingBotEmulateMozilla",
58 ua: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/41.0.2272.96 Mobile Safari/537.36 Edg/80.0.345.0",
59 expected: "Mozilla:5.0 Browser:bingbot-2.0 Bot:true Mobile:true",
60 },
61 {
4762 title: "BaiduBot",
4863 ua: "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)",
4964 expected: "Mozilla:5.0 Browser:Baiduspider-2.0 Bot:true Mobile:false",
102117 title: "AdsBotGoogleMobile",
103118 ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)",
104119 expected: "Mozilla:5.0 Browser:AdsBot-Google-Mobile Bot:true Mobile:true",
120 },
121 {
122 title: "APIs-Google",
123 ua: "APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)",
124 expected: "Browser:APIs-Google Bot:true Mobile:false",
125 },
126 {
127 title: "iMessage-preview",
128 ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0",
129 expected: "Mozilla:5.0 Platform:Macintosh Browser:iMessage-Preview-9.0.1 Bot:true Mobile:false",
105130 },
106131
107132 // Internet Explorer
184209 expected: "Mozilla:5.0 Platform:Windows OS:Windows Phone 10.0 Browser:Edge-12.10240 Engine:EdgeHTML Bot:false Mobile:true",
185210 },
186211
212 // Microsoft Chromium Edge
213 {
214 title: "EdgeDesktop",
215 ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 Edg/83.0.478.37",
216 expected: "Mozilla:5.0 Platform:Windows OS:Windows 10 Browser:Edge-83.0.478.37 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
217 expectedOS: &OSInfo{"Windows 10", "Windows", "10"},
218 },
219
187220 // Gecko
188221 {
189222 title: "FirefoxMac",
403436 ua: "curl/7.28.1",
404437 expected: "Browser:curl-7.28.1 Bot:false Mobile:false",
405438 },
439 {
440 title: "OkHttp",
441 ua: "okhttp/4.2.2",
442 expected: "Browser:OkHttp-4.2.2 Bot:false Mobile:true",
443 },
406444
407445 // WebKit
408446 {
540578 ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4",
541579 expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 8_3 like Mac OS X Browser:Firefox-1.0 Engine:AppleWebKit-600.1.4 Bot:false Mobile:true",
542580 },
581 {
582 title: "Firefox Focus for iOS",
583 ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/7.0.4 Mobile/16B91 Safari/605.1.15",
584 expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 12_1 like Mac OS X Browser:Firefox-7.0.4 Engine:AppleWebKit-605.1.15 Bot:false Mobile:true",
585 },
586 {
587 title: "Firefox on iPad",
588 ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/24.1 Safari/605.1.15",
589 expected: "Mozilla:5.0 Platform:iPad OS:Intel Mac OS X 10.15 Browser:Firefox-24.1 Engine:AppleWebKit-605.1.15 Bot:false Mobile:true",
590 },
591 {
592 title: "Electron",
593 ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) CozyDrive/3.17.0 Chrome/73.0.3683.119 Electron/5.0.0 Safari/537.36",
594 expected: "Mozilla:5.0 Platform:Windows OS:Windows 10 Browser:Electron-5.0.0 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
595 },
543596
544597 // Dalvik
545598 {
582635 title: "Facebook - No Browser Or OS",
583636 ua: "[FBAN/FB4A;FBAV/16.0.0.20.15;FBBV/4061184;FBDM/{density=1.5,width=540,height=960};FBLC/en_US;FB_FW/2;FBCR/MY CELCOM;FBPN/com.facebook.katana;FBDV/Lenovo A850+;FBSV/4.2.2;FBOP/1;FBCA/armeabi-v7a:armeabi;]",
584637 expected: "Bot:false Mobile:false",
638 },
639
640 // arm_64
641 {
642 title: "Samsung S7 Edge - YaBrowser",
643 ua: "Mozilla/5.0 (Linux; arm_64; Android 8.0.0; SM-G935F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 YaBrowser/19.12.3.101.00 Mobile Safari/537.36",
644 expected: "Mozilla:5.0 Platform:Linux OS:Android 8.0.0 Localization:SM-G935F Browser:YaBrowser-19.12.3.101.00 Engine:AppleWebKit-537.36 Bot:false Mobile:true",
645 },
646 {
647 title: "HUAWEI P20 lite - YaBrowser",
648 ua: "Mozilla/5.0 (Linux; arm_64; Android 9; ANE-LX2J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 YaBrowser/20.2.6.114.00 Mobile Safari/537.36",
649 expected: "Mozilla:5.0 Platform:Linux OS:Android 9 Localization:ANE-LX2J Browser:YaBrowser-20.2.6.114.00 Engine:AppleWebKit-537.36 Bot:false Mobile:true",
585650 },
586651 }
587652
0 // Copyright (C) 2014-2019 Miquel Sabaté Solà <mikisabate@gmail.com>
0 // Copyright (C) 2014-2021 Miquel Sabaté Solà <mikisabate@gmail.com>
11 // This file is licensed under the MIT license.
22 // See the LICENSE file.
33
88 "strings"
99 )
1010
11 var botFromSiteRegexp = regexp.MustCompile("http://.+\\.\\w+")
11 var botFromSiteRegexp = regexp.MustCompile("http[s]?://.+\\.\\w+")
1212
1313 // Get the name of the bot from the website that may be in the given comment. If
1414 // there is no website in the comment, then an empty string is returned.
4141 }
4242
4343 // Returns true if the info that we currently have corresponds to the Google
44 // mobile bot. This function also modifies some attributes in the receiver
44 // or Bing mobile bot. This function also modifies some attributes in the receiver
4545 // accordingly.
46 func (p *UserAgent) googleBot() bool {
47 // This is a hackish way to detect Google's mobile bot (Googlebot, AdsBot-Google-Mobile, etc.).
48 // See https://support.google.com/webmasters/answer/1061943
49 if strings.Index(p.ua, "Google") != -1 {
46 func (p *UserAgent) googleOrBingBot() bool {
47 // This is a hackish way to detect
48 // Google's mobile bot (Googlebot, AdsBot-Google-Mobile, etc.)
49 // (See https://support.google.com/webmasters/answer/1061943)
50 // and Bing's mobile bot
51 // (See https://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0)
52 if strings.Index(p.ua, "Google") != -1 || strings.Index(p.ua, "bingbot") != -1 {
5053 p.platform = ""
5154 p.undecided = true
5255 }
5356 return p.undecided
57 }
58
59 // Returns true if we think that it is iMessage-Preview. This function also
60 // modifies some attributes in the receiver accordingly.
61 func (p *UserAgent) iMessagePreview() bool {
62 // iMessage-Preview doesn't advertise itself. We have a to rely on a hack
63 // to detect it: it impersonates both facebook and twitter bots.
64 // See https://medium.com/@siggi/apples-imessage-impersonates-twitter-facebook-bots-when-scraping-cef85b2cbb7d
65 if strings.Index(p.ua, "facebookexternalhit") == -1 {
66 return false
67 }
68 if strings.Index(p.ua, "Twitterbot") == -1 {
69 return false
70 }
71 p.bot = true
72 p.browser.Name = "iMessage-Preview"
73 p.browser.Engine = ""
74 p.browser.EngineVersion = ""
75 // We don't set the mobile flag because iMessage can be on iOS (mobile) or macOS (not mobile).
76 return true
5477 }
5578
5679 // Set the attributes of the receiver as given by the parameters. All the other
0 // Copyright (C) 2012-2019 Miquel Sabaté Solà <mikisabate@gmail.com>
0 // Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com>
11 // This file is licensed under the MIT license.
22 // See the LICENSE file.
33
1010
1111 var ie11Regexp = regexp.MustCompile("^rv:(.+)$")
1212
13 // A struct containing all the information that we might be
13 // Browser is a struct containing all the information that we might be
1414 // interested from the browser.
1515 type Browser struct {
1616 // The name of the browser's engine.
5858 }
5959 p.browser.Version = sections[sectionIndex].version
6060 if engine.name == "AppleWebKit" {
61 for _, comment := range engine.comment {
62 if len(comment) > 5 &&
63 (strings.HasPrefix(comment, "Googlebot") || strings.HasPrefix(comment, "bingbot")) {
64 p.undecided = true
65 break
66 }
67 }
6168 switch sections[slen-1].name {
6269 case "Edge":
6370 p.browser.Name = "Edge"
6471 p.browser.Version = sections[slen-1].version
6572 p.browser.Engine = "EdgeHTML"
6673 p.browser.EngineVersion = ""
74 case "Edg":
75 if p.undecided != true {
76 p.browser.Name = "Edge"
77 p.browser.Version = sections[slen-1].version
78 p.browser.Engine = "AppleWebKit"
79 p.browser.EngineVersion = sections[slen-2].version
80 }
6781 case "OPR":
6882 p.browser.Name = "Opera"
6983 p.browser.Version = sections[slen-1].version
7387 p.browser.Name = "YaBrowser"
7488 p.browser.Version = sections[slen-3].version
7589 default:
76 switch sections[sectionIndex].name {
77 case "Chrome", "CriOS":
78 p.browser.Name = "Chrome"
79 case "Chromium":
80 p.browser.Name = "Chromium"
81 case "FxiOS":
82 p.browser.Name = "Firefox"
90 switch sections[slen-2].name {
91 case "Electron":
92 p.browser.Name = "Electron"
93 p.browser.Version = sections[slen-2].version
8394 default:
84 p.browser.Name = "Safari"
95 switch sections[sectionIndex].name {
96 case "Chrome", "CriOS":
97 p.browser.Name = "Chrome"
98 case "Chromium":
99 p.browser.Name = "Chromium"
100 case "FxiOS":
101 p.browser.Name = "Firefox"
102 default:
103 p.browser.Name = "Safari"
104 }
85105 }
86106 }
87107 // It's possible the google-bot emulates these now
88108 for _, comment := range engine.comment {
89 if len(comment) > 5 && strings.HasPrefix(comment, "Googlebot") {
109 if len(comment) > 5 &&
110 (strings.HasPrefix(comment, "Googlebot") || strings.HasPrefix(comment, "bingbot")) {
90111 p.undecided = true
91112 break
92113 }
0 #!/bin/bash
1 # Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com>
2 # This file is licensed under the MIT license.
3 # See the LICENSE file.
4
5 # Hack so we work around old versions of Go which are no longer supported by
6 # linting tools that we use in this project.
7
8 case "${TRAVIS_GO_VERSION:2:1}" in
9 "4" | "5" | "6" | "7" | "8")
10 echo "This version of Go is not going to use linting tools."
11 ;;
12 *)
13 go get -u github.com/vbatts/git-validation
14 go get -u golang.org/x/lint/golint
15 ;;
16 esac
0 #!/bin/bash
1 # Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com>
2 # This file is licensed under the MIT license.
3 # See the LICENSE file.
4
5 # Idea taken from: https://github.com/golang/lint/issues/263#issuecomment-590070899
6 #
7 # The thing here is that I named the package with an underscore, and that was
8 # done way before coding conventions and such were enforced with tools like
9 # golint, so these kinds of rules were not taken into consideration.
10 #
11 # For compatibility reasons I'm wary of renaming this package, so I'll just
12 # ignore this rule.
13
14 # Hack so we work around old versions of Go which are no longer supported by
15 # linting tools that we use in this project.
16
17 case "${TRAVIS_GO_VERSION:2:1}" in
18 "4" | "5" | "6" | "7" | "8")
19 echo "This version of Go is not going to use golint."
20 exit 0
21 ;;
22 esac
23
24 which golint >/dev/null 2>/dev/null || (echo "ERROR: golint not found." && false)
25
26 # Patterns to be ignored from the go lint output
27 IGNORED_PATTERNS=(
28 "don't use an underscore in package name"
29 )
30
31 # Patterns joined into a regular expression
32 REGEX=$(printf "|(%s)" "${IGNORED_PATTERNS[@]}")
33 REGEX=${REGEX:1}
34
35 # Execute go lint on all the files and filter output by the regualr expression
36 output=$( ( (golint ./... | egrep -v "$REGEX") 2>&1 ) | tee /dev/fd/2);
37 if [ -z "$output" ]
38 then
39 exit 0
40 else
41 exit 1
42 fi
+0
-8
codelingo.yaml less more
0 tenets:
1 - import: codelingo/effective-go/comment-first-word-as-subject
2 - import: codelingo/effective-go/avoid-annotations-in-comments
3 - import: codelingo/effective-go/underscores-in-name
4 - import: codelingo/go/golint
5 - import: codelingo/go/global-var
6 - import: codelingo/go/tested
7 - import: codelingo/lightning-network-daemon
0 // Copyright (C) 2012-2019 Miquel Sabaté Solà <mikisabate@gmail.com>
0 // Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com>
11 // This file is licensed under the MIT license.
22 // See the LICENSE file.
33
44 package user_agent
55
6 import "strings"
7
8 // Represents full information on the operating system extracted from the user agent.
6 import (
7 "strings"
8 )
9
10 // OSInfo represents full information on the operating system extracted from the
11 // user agent.
912 type OSInfo struct {
1013 // Full name of the operating system. This is identical to the output of ua.OS()
1114 FullName string
7477 p.browser.Name = "Android"
7578 }
7679 if len(comment) > 1 {
77 if comment[1] == "U" {
80 if comment[1] == "U" || comment[1] == "arm_64" {
7881 if len(comment) > 2 {
7982 p.os = comment[2]
8083 } else {
8891 if len(comment) > 3 {
8992 p.localization = comment[3]
9093 } else if len(comment) == 3 {
91 _ = p.googleBot()
94 _ = p.googleOrBingBot()
9295 }
9396 } else if len(comment) > 0 {
9497 if len(comment) > 3 {
99102 } else if len(comment) < 2 {
100103 p.localization = comment[0]
101104 } else if len(comment) < 3 {
102 if !p.googleBot() {
105 if !p.googleOrBingBot() && !p.iMessagePreview() {
103106 p.os = normalizeOS(comment[1])
104107 }
105108 } else {
112115 }
113116 }
114117 }
118
119 // Special case for Firefox on iPad, where the platform is advertised as Macintosh instead of iPad
120 if p.platform == "Macintosh" && p.browser.Engine == "AppleWebKit" && p.browser.Name == "Firefox" {
121 p.platform = "iPad"
122 p.mobile = true
123 }
115124 }
116125
117126 // Guess the OS, the localization and if this is a mobile device
121130 // argument is a slice of strings containing the comment.
122131 func gecko(p *UserAgent, comment []string) {
123132 if len(comment) > 1 {
124 if comment[1] == "U" {
133 if comment[1] == "U" || comment[1] == "arm_64" {
125134 if len(comment) > 2 {
126135 p.os = normalizeOS(comment[2])
127136 } else {
275284 if len(s.comment) > 0 {
276285 dalvik(p, s.comment)
277286 }
287 } else if s.name == "okhttp" {
288 p.mobile = true
289 p.browser.Name = "OkHttp"
290 p.browser.Version = s.version
278291 } else {
279292 // Check whether this is a bot or just a weird browser.
280293 p.undecided = true
0 // Copyright (C) 2012-2019 Miquel Sabaté Solà <mikisabate@gmail.com>
0 // Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com>
11 // This file is licensed under the MIT license.
22 // See the LICENSE file.
33
124124 p.undecided = false
125125 }
126126
127 // Parse the given User-Agent string and get the resulting UserAgent object.
127 // New parses the given User-Agent string and get the resulting UserAgent
128 // object.
128129 //
129130 // Returns an UserAgent object that has been initialized after parsing
130131 // the given User-Agent string.