The false/true strings are no longer converted to 0/1 with PHP 5.3, in _browscap_import(). Instead they are imported as the literal strings 'false' or 'true' so that they always evaluate to true when cast to booleans.

Maybe the source file format has changed from Win to Unix with the change of the remote repository URL?

To test, put this in an _init function:

  $browser = browscap_get_browser();
  dsm($browser);
  if ($browser['ismobiledevice']) {
    dsm($browser['ismobiledevice'], "$browser['ismobiledevice'] evaluates to true");
  }

And then refresh the data using the steps described below.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake’s picture

The patch attached, that replaces strtr with preg_replace, works for me.

mondrake’s picture

Status: Active » Needs review

status change

jlea9378’s picture

The patch fixed the problem for me!

Jeff Burnz’s picture

acy76’s picture

Version: 7.x-2.x-dev » 7.x-2.0
Status: Needs review » Reviewed & tested by the community

Patched against 7.x-2.0, uninstalled , reinstalled and panels are now detecting mobile browsers properly with browscap_ctools module (important - full uninstall rather than disable/enable required to trigger hook_schema; otherwise, not certain if simple browscap DB update will cause old data to be properly replaced in the browscap table).

EDIT: Rather than uninstalling/reinstalling browscap, the module itself can be used to import a new dataset:
Modules>Browscap>Refresh Browscap Data File then Save Configuration.

Thanks to IEFBR14 for the tip (here).

mondrake’s picture

Re. #5, 'Refresh Browscap Data File' can only work 'once' as long as the local version of the imported browscap.ini is older than the version available on the remote BCP repository. Browscap implements a version check before importing the file from the remote repository. This is at least my understanding :)

In case your setup is already on version 5016 (current at the time of posting this comment), most probably the only possible solution is uninstall/reinstall.

Alternatively, you may want to review and test patch in comment #3 of #1788720: Allow to change the URLs to use for importing useragent information. That patch implements a new button 'Force reload' in the browscap admin form, that bypasses the version check and fetches the remote file unconditionally.

awasson’s picture

@mondrake: Thanks for the patch; it worked exactly as described.

Does anyone know if this will be committed to the next update of the module?

Andrew

ptmkenny’s picture

Patch #1 fixed the issue for me as well.

Lendude’s picture

#1 implemented and fixed my issues

progpapa’s picture

+1 for the patch in #1

Please note that this impacts other modules that work together with Browscap. I'm using the Statistics Filter module, which has a Browscap integration but without this patch the statistics_filter_is_crawler function considers all traffic to be a crawler.

greggles’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Status: Reviewed & tested by the community » Needs review

I tried to repeat the problem but I don't see the bug. It would be super helpful to have a simpletest for this problem so that people can confirm the problem is fixed and doesn't come back.

I did create a regexpal test with current code and the proposed pattern.

It does seem like we should make this change, but it would be good to know specifically an example bug this causes so I can see before/after. I am working with php 5.3.

Since this is still present in the dev version that is the best version for the issue.

Since it's not 100% clear what bug this fixes marking back to needs review.

greggles’s picture

Title: False/true not converted to 0/1 during browscap.ini import with PHP 5.3 » False/true not converted to 0/1 during browscap.ini import
Version: 7.x-2.x-dev » 7.x-1.x-dev
Priority: Normal » Critical
Status: Needs review » Patch (to be ported)

OK, so I tested this some more and think it is a critical bug that is indeed RTBC. I updated the original post to make it more clear.

I think it's worth committing this fix now to get it into the dev package at least. http://drupalcode.org/project/browscap.git/commit/b09a91f

Backports to 7.x-1.x and 6.x-2.x and 6.x-1.x are welcome.

jlea9378’s picture

Did you intend to change the version from 7.x-2.x to 7.x-1.x?

greggles’s picture

@jlea I did because the code is committed and I believe the bug is now fixed in 7.x-2.x-dev. It's now "to be ported" to the previous branch (I don't plan to work on that, but someone else could and I would commit it).

greggles’s picture

Issue summary: View changes

providing more clarity on the problem.

AohRveTPV’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Issue summary: View changes

There is no supported release for the 7.x-1.x branch, so a port to it is no longer needed. Please correct if wrong.

AohRveTPV’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

Reproduced problem in 6.x-2.x and confirmed patch in #1 fixes. Patch applies as is.

greggles’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the research, AohRveTPV - committed with credit to you and mondrake.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

computerwill’s picture

FYI: I had to modify the code on my patch after updating from browscap 6.x-2.0 to 6.x-2.1. I was updating a site which I had previously patched successfully with this patch on 6.x-2.0, but browscap wasn't working properly.

It's worth noting that my import.inc also has a few other changes to compensate for our firewall, but I don't think that is relevant to the problem I was having. The problem I had on my site was that all browsers were being detected as mobile browsers.

After comparing the databases on my live site and my testing site, I believe the schema changed when transitioning from tempdownloads.browserscap.com to www.browscap.org. True and False are now reported with quotes around them. The previous regular expression was only good for unquoted True and False after an equal sign.
I changed the following lines of the patch to import.inc to account for optional quotes. Maybe someone more familiar with this can convert it to a proper patch of the aforementioned patch:
Change old:

    $browscap_data = preg_replace(
      array(
        "/=\s*true\s*\n/",
        "/=\s*false\s*\n/",
      ),
      array(
        "=1\n",
        "=0\n",
      ),
      $browscap_data
    );

to

    $browscap_data = preg_replace(
      array(
        "/=[\s\"]*true[\s\"]*\n/",
        "/=[\s\"]*false[\s\"]*\n/",
      ),
      array(
        "=1\n",
        "=0\n",
      ),
      $browscap_data
    );

It's rudimentary, but it worked for me. I also had to temporarily decrement local_version after line 15 to force it to download the same file again ($local_version--; #uncomment this line to force download)

AohRveTPV’s picture

Priority: Critical » Normal
Status: Closed (fixed) » Active

Re-opening per #19. I have not tried to reproduce the problem yet.

Also changing to normal severity because I do not immediately see how this would be critical.

computerwill’s picture

For anyone who is wondering, I would say that it's only as critical as how you use true/false data from browscap. In essence, the data format change puts us back to the original problem that started this thread (which was normal severity as well). Sites will be impacted to various degrees from zero to critical.

In my case, it was semi-critical because it completely altered our site's appearance for visitors using non-mobile browsers, reverting to a very basic theme.

Thanks for contributing your time and checking on this.

AohRveTPV’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Priority: Normal » Major

"Critical" does not seem appropriate to me per the descriptions of the priority levels:
https://www.drupal.org/node/45111

However I see how it could be considered critical for a given site if some important functionality depends on the testing a TRUE/FALSE property. Upgrading to "Major".

Looks like this also affects 7.x-2.x.

AohRveTPV’s picture

Status: Active » Needs review
FileSize
428 bytes
693 bytes

7.x-2.x patch I have tested and it seems to convert all "true" and "false". 6.x-2.x is currently untested.

I changed the regular expression a bit versus suggested in #19 to be more specific. I don't think we need to handle multiple consecutive double quotes, spaces within the double quotes, etc.

Please review/test.

AohRveTPV’s picture

Made a minor simplification to the parameters to preg_replace().

Patches in #23 newly used single quotes for one preg_replace() parameter and double quotes for the other. These patches consistently use single quotes for both.

ponies’s picture

#24 works for me on 7.x.

Irisibk’s picture

#24 works for me on 7x too.

AohRveTPV’s picture

Status: Needs review » Reviewed & tested by the community
AohRveTPV’s picture

Status: Reviewed & tested by the community » Needs review

Was wrong to set this RTBC. You're not supposed to set your own patch to RTBC.

dczaretsky’s picture

#24 didn't work for me. Seems to be possibly removing all the EOLs. I believe you need to maintain the \n characters, which require the double-quote. Here is the modified code from #24 that works for me:

    $browscap_data = preg_replace(
      array(
        "/=\s*\"?true\"?\s*$/m",
        "/=\s*\"?false\"?\s*$/m",
      ),
      array(
        "=1\n",
        "=0\n",
      ),
      $browscap_data
    );

  • 93b172b committed on 8.x-3.x
    Issue #1868808 - False/true not converted to 0/1 during browscap.ini...