Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

YandexBot is not detected as a bot on iPhone. #72

@denisbiryukov

Description

@denisbiryukov

There are several 'User-Agent' kinds of 'YandexBot': https://user-agents.net/bots/yandexbot

The following kind is not detected as a bot:
https://user-agents.net/string/mozilla-5-0-iphone-cpu-iphone-os-8-1-like-mac-os-x-applewebkit-600-1-4-khtml-like-gecko-version-8-0-mobile-12b411-safari-600-1-4-compatible-yandexbot-3-0-http-yandex-com-bots

Steps to reproduce the problem:
var ua user_agent.UserAgent
userAgent := "Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
// Parse a User-Agent inners.
ua.Parse(userAgent)
// Check either a bot or not.
ua.Bot() // == false

Expected result:
ua.Bot() // == true

Verified solution:
`

diff --git a/CHANGELOG.md b/CHANGELOG.md

  • Fix detection of Firefox on iPad.
  • Fix detection of Linux ARM-based Android.
  • Add detection of Chromium Edge on Windows.
    +- Add detection of YandexBot on iPhone.

diff --git a/bot.go b/bot.go

-// Returns true if the info that we currently have corresponds to the Google
+// Returns true if the info that we currently have corresponds to the Google or Yandex
-func (p *UserAgent) googleOrBingBot() bool {
+func (p *UserAgent) googleOrBingBotOrYandex() bool {
// This is a hackish way to detect
// Google's mobile bot (Googlebot, AdsBot-Google-Mobile, etc.)
// (See https://support.google.com/webmasters/answer/1061943)
// and Bing's mobile bot
// (See https://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0)

  •   if strings.Index(p.ua, "Google") != -1 || strings.Index(p.ua, "bingbot") != -1 {
    
  •   // and Yandex's mobile bot
    
  •   // (See https://yandex.ru/support/webmaster/robot-workings/check-yandex-robots.html)
    
  •   if strings.Index(p.ua, "Google") != -1 || strings.Index(p.ua, "bingbot") != -1 || strings.Index(p.ua, "Yandex") != -1 {
    

diff --git a/operating_systems.go b/operating_systems.go

  •                   _ = p.googleOrBingBot()
    
  •                   _ = p.googleOrBingBotOrYandex()
    
  •                   if !p.googleOrBingBot() && !p.iMessagePreview() {
    
  •                   if !p.googleOrBingBotOrYandex() && !p.iMessagePreview() {
    

`

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions