ua-parser / uap-scala

Scala port of ua-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception for 'real' UserAgent header

soyl opened this issue · comments

Hi,

we are seeing a lot of parse failures in our logs for header values coming from actual client requests, but have no clue what is wrong:

Example:

Mozilla/5.0 (Linux; Android 5.0; SM-N9005 Build/LRX21V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36

Exception:

j.l.NullPointerException: null
at j.util.regex.Matcher.quoteReplacement(Matcher.java:655) ~[na:1.7.0_51]
at u.p.Device$DevicePattern$$anonfun$process$1.apply(Device.scala:17) ~[uap-scala_2.11-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
at u.p.Device$DevicePattern$$anonfun$process$1.apply(Device.scala:15)
at scala.Option.map(Option.scala:146) ~[scala-library-2.11.6.jar:0.13.6]
at u.p.Device$DevicePattern.process(Device.scala:15) ~[uap-scala_2.11-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
at u.p.Device$DeviceParser$$anonfun$parse$1.apply(Device.scala:31)
at u.p.Device$DeviceParser$$anonfun$parse$1.apply(Device.scala:30)
at s.c.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:124) ~[scala-library-2.11.6.jar:0.13.6]
at s.c.immutable.List.foldLeft(List.scala:84) [scala-library-2.11.6.jar:0.13.6]
at u.p.Device$DeviceParser.parse(Device.scala:30) ~[uap-scala_2.11-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
at ua.parser.Parser.parse(Parser.scala:15)
at u.p.CachingParser$$anonfun$parse$1.apply(CachingParser.scala:10)
at u.p.CachingParser$$anonfun$parse$1.apply(CachingParser.scala:9)
at scala.Option.getOrElse(Option.scala:121) ~[scala-library-2.11.6.jar:0.13.6]
at u.p.CachingParser.parse(CachingParser.scala:9) ~[uap-scala_2.11-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
at d.g.b.i.u.UserAgentParser$$anonfun$receive$1$$anonfun$1.apply(UserAgentParser.scala:19)

Hi again,

the problem seems to be the '/' inside the comment:

Mozilla/5.0 (Linux; Android 5.0; SM-N9005 Build/LRX21V)

This is allowed by the spec but causes the parser to fail.

Can you please look into this?

Jan

I've recently updated this library to use the latest https://github.com/ua-parser/uap-core and did some refactoring. I tested the 2 UA you provided as examples above, and they're properly parsed as follows

Mozilla/5.0 (Linux; Android 5.0; SM-N9005 Build/LRX21V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36
Client(UserAgent(Chrome Mobile,Some(47),Some(0),Some(2526)),OS(Android,Some(5),Some(0),None,None),Device(Samsung SM-N9005,Some(Samsung),Some(SM-N9005)))

Mozilla/5.0 (Linux; Android 5.0; SM-N9005 Build/LRX21V)
Client(UserAgent(Android,Some(5),Some(0),None),OS(Android,Some(5),Some(0),None,None),Device(Samsung SM-N9005,Some(Samsung),Some(SM-N9005)))

I'll close this as I cannot reproduce this problem in the latest uap-scala version. If your problem persists in the latest version, please open a new issue and let's take it from there.