podigee/device_detector

Upstream patterns can't be updated due to Ruby Regex error

Closed this issue · 2 comments

When updating to latest upstream regexes tests are failing for a string with special charater, eg:

6) Error:
DeviceDetector::smartphone-7.yml::Mozilla/5.0 (Linux; U; Android 2.3.6; pt-br; XT321 Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Versão/4.0 Mobile Safari/533.1#test_0001_should be detected:
RegexpError: invalid pattern in look-behind: /(?:^|[^A-Z0-9\-_]|[^A-Z0-9\-]_|sprd-)(?:acer|(?<!ZTE BLADE |ImSmart |ERGO |X-Style Tab )a(?:101|110|2[10]0|211|50[10]|51[10]|70[10])[);\/ ]|Android.*V3[67]0[);\/ ]|Android.*Z1[23456]0 Build|Android.*Z5\d{2} Build|Android.*T0[234678] Build|Android.*S55[);\/ ]|A1-830|A1-81[01]|A1-7[23]4|A3-A[1234][01]|B1-7[1235678][01]|B1-7[23]3|B1-8[1235]0|B1-A71|B3-A[12]0|B3-A3[02]|E39[);\/ ]|S5[12]0 Build|DA[0-9]+HQ?L[);\/ ]|Aspire V5-121|Predator G9-793|GT-810)/i

Source regexp that is causing the issue:
https://github.com/matomo-org/device-detector/blob/118651c4fbff739e7f29acebd1732e7ccbf238a7/regexes/device/mobiles.yml#L735

This seems to be related to a bug in Ruby Regexp
https://bugs.ruby-lang.org/issues/13671

Until the problem is fixed a workaround needs to be implemented. One quick option would be to fail silently when this happens, but that's obviously not a good solution. Any ideas?

I found a related issue over there some time ago. It was briefly discussed here:

matomo-org/device-detector#5970

In the end I adjusted the RegEx and removed the related fixtures. I think given the device(s) that is tested with this Regex, the consequences of removing it should be negligible compared to the benefit of using the latest definitions.

@spiderpug FYI. In our fork, I ended up solving it by cleaning the input string in case of an error
https://github.com/castle/device_detector/pull/3/files#diff-b9c1533938d0d1b5f642ea2c6c2f6d8d