Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#24 | browscap-6.x-2.x-fix_bools-24.patch | 689 bytes | AohRveTPV |
#24 | browscap-7.x-2.x-fix_bools-24.patch | 517 bytes | AohRveTPV |
#23 | browscap-6.x-2.x-fix_bools-23.patch | 693 bytes | AohRveTPV |
#23 | browscap-7.x-2.x-fix_bools-23.patch | 428 bytes | AohRveTPV |
#1 | browscap_fix-bools-1868808-1.patch | 685 bytes | mondrake |
Comments
Comment #1
mondrakeThe patch attached, that replaces strtr with preg_replace, works for me.
Comment #2
mondrakestatus change
Comment #3
jlea9378 CreditAttribution: jlea9378 commentedThe patch fixed the problem for me!
Comment #4
Jeff Burnz CreditAttribution: Jeff Burnz commentedRelated I believe: #1861832: browscap_ctools_browscap_access_ctools_access_check returns false on mobile-devices
Comment #5
acy76 CreditAttribution: acy76 commentedPatched 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).
Comment #6
mondrakeRe. #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.
Comment #7
awasson CreditAttribution: awasson commented@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
Comment #8
ptmkenny CreditAttribution: ptmkenny commentedPatch #1 fixed the issue for me as well.
Comment #9
Lendude#1 implemented and fixed my issues
Comment #10
progpapa CreditAttribution: progpapa commented+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.Comment #11
gregglesI 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.
Comment #12
gregglesOK, 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.
Comment #13
jlea9378 CreditAttribution: jlea9378 commentedDid you intend to change the version from 7.x-2.x to 7.x-1.x?
Comment #14
greggles@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).
Comment #14.0
gregglesproviding more clarity on the problem.
Comment #15
AohRveTPV CreditAttribution: AohRveTPV commentedThere is no supported release for the 7.x-1.x branch, so a port to it is no longer needed. Please correct if wrong.
Comment #16
AohRveTPV CreditAttribution: AohRveTPV commentedReproduced problem in 6.x-2.x and confirmed patch in #1 fixes. Patch applies as is.
Comment #17
gregglesThanks for the research, AohRveTPV - committed with credit to you and mondrake.
Comment #19
computerwill CreditAttribution: computerwill as a volunteer commentedFYI: 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:
to
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
)Comment #20
AohRveTPV CreditAttribution: AohRveTPV commentedRe-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.
Comment #21
computerwill CreditAttribution: computerwill as a volunteer commentedFor 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.
Comment #22
AohRveTPV CreditAttribution: AohRveTPV commented"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.
Comment #23
AohRveTPV CreditAttribution: AohRveTPV commented7.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.
Comment #24
AohRveTPV CreditAttribution: AohRveTPV commentedMade 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.Comment #25
ponies#24 works for me on 7.x.
Comment #26
Irisibk CreditAttribution: Irisibk commented#24 works for me on 7x too.
Comment #27
AohRveTPV CreditAttribution: AohRveTPV commentedComment #28
AohRveTPV CreditAttribution: AohRveTPV commentedWas wrong to set this RTBC. You're not supposed to set your own patch to RTBC.
Comment #29
dczaretsky CreditAttribution: dczaretsky commented#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: