From 3fc6592559ab51ec0e85d1fd5b085939493c94d7 Mon Sep 17 00:00:00 2001 From: David Armstrong Lewis Date: Thu, 17 Feb 2022 18:38:58 -0800 Subject: [PATCH] Release 0.5.1 - Exit early in device and OS matchers (#11) <@jan-auer> --- Cargo.toml | 2 +- flake.lock | 18 +++++++++--------- nix/shell.nix | 1 + src/parser/device.rs | 4 ++++ src/parser/os.rs | 4 ++++ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 57439d7..1f0aec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uaparser" -version = "0.5.0" +version = "0.5.1" description = "A Rust implementation of the UA Parser" license = "MIT" authors = ["David Lewis "] diff --git a/flake.lock b/flake.lock index 9246d13..327dc99 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1638122382, - "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", "owner": "numtide", "repo": "flake-utils", - "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", "type": "github" }, "original": { @@ -32,11 +32,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1642160200, - "narHash": "sha256-5mb1nvh2vWlnKvyJzGNKsL7AQRFk+H5E/Xh83fTzYG4=", + "lastModified": 1644972330, + "narHash": "sha256-6V2JFpTUzB9G+KcqtUR1yl7f6rd9495YrFECslEmbGw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e5a50e8f2995ff359a170d52cc40adbcfdd92ba4", + "rev": "19574af0af3ffaf7c9e359744ed32556f34536bd", "type": "github" }, "original": { @@ -75,11 +75,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1642473686, - "narHash": "sha256-VUbbTu6NJFlGaVEsXfwWQeypQPGAobs4UUbyxNZVzA0=", + "lastModified": 1645064920, + "narHash": "sha256-MA1TWy+XGnFWHH1EAxZ943UOEBqYTToubV9w4+r/cbE=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "37c9180fb097943e5427de21acba86a47c5f0f71", + "rev": "66a6dd1e56fca9a42dd18c3616dc66c25ff8d204", "type": "github" }, "original": { diff --git a/nix/shell.nix b/nix/shell.nix index 9aa5e90..22f0051 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -9,5 +9,6 @@ mkShell { extensions = [ "rust-src" ]; }) cargo-criterion + gnuplot ]; } diff --git a/src/parser/device.rs b/src/parser/device.rs index 2e74182..d5e00fe 100644 --- a/src/parser/device.rs +++ b/src/parser/device.rs @@ -17,6 +17,10 @@ impl SubParser for Matcher { type Item = Device; fn try_parse(&self, text: &str) -> Option { + if !self.regex.is_match(text) { + return None; + } + if let Some(captures) = self.regex.captures(text) { let family: String = if let Some(device_replacement) = &self.device_replacement { diff --git a/src/parser/os.rs b/src/parser/os.rs index 21460c0..1ea11f5 100644 --- a/src/parser/os.rs +++ b/src/parser/os.rs @@ -18,6 +18,10 @@ impl SubParser for Matcher { type Item = OS; fn try_parse(&self, text: &str) -> Option { + if !self.regex.is_match(text) { + return None; + } + if let Some(captures) = self.regex.captures(text) { let family: String = if let Some(os_replacement) = &self.os_replacement { replace(os_replacement, &captures)