Skip to content

Commit ec9d60d

Browse files
authored
Merge pull request #76 from mmuruev/feature/upgrade-versions
2 parents 9176a46 + be009c4 commit ec9d60d

5 files changed

Lines changed: 49 additions & 16 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ Maven
1515
</dependency>
1616
```
1717

18+
Gradle(Kotlin)
19+
```
20+
implementation("com.github.ua-parser:uap-java:1.5.3")
21+
```
22+
1823
SBT
1924
```
2025
"com.github.ua-parser" % "uap-java" % "1.5.3"

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@
8787
<plugin>
8888
<groupId>org.apache.maven.plugins</groupId>
8989
<artifactId>maven-compiler-plugin</artifactId>
90-
<version>3.8.1</version>
90+
<version>3.10.1</version>
9191
<configuration>
92-
<source>1.7</source>
93-
<target>1.7</target>
92+
<source>1.8</source>
93+
<target>1.8</target>
9494
</configuration>
9595
</plugin>
9696
</plugins>
@@ -104,7 +104,7 @@
104104
<plugin>
105105
<groupId>org.apache.maven.plugins</groupId>
106106
<artifactId>maven-source-plugin</artifactId>
107-
<version>3.2.0</version>
107+
<version>3.2.1</version>
108108
<executions>
109109
<execution>
110110
<id>attach-sources</id>
@@ -118,9 +118,9 @@
118118
<plugin>
119119
<groupId>org.apache.maven.plugins</groupId>
120120
<artifactId>maven-javadoc-plugin</artifactId>
121-
<version>3.2.0</version>
121+
<version>3.4.1</version>
122122
<configuration>
123-
<source>1.7</source>
123+
<source>1.8</source>
124124
</configuration>
125125
<executions>
126126
<execution>
@@ -135,7 +135,7 @@
135135
<plugin>
136136
<groupId>org.apache.maven.plugins</groupId>
137137
<artifactId>maven-gpg-plugin</artifactId>
138-
<version>1.6</version>
138+
<version>3.0.1</version>
139139
<executions>
140140
<execution>
141141
<id>sign-artifacts</id>
@@ -160,12 +160,12 @@
160160
<dependency>
161161
<groupId>org.apache.commons</groupId>
162162
<artifactId>commons-collections4</artifactId>
163-
<version>4.1</version>
163+
<version>4.4</version>
164164
</dependency>
165165
<dependency>
166166
<groupId>junit</groupId>
167167
<artifactId>junit</artifactId>
168-
<version>4.13.1</version>
168+
<version>4.13.2</version>
169169
<scope>test</scope>
170170
</dependency>
171171
<dependency>

src/main/java/ua_parser/Parser.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import org.yaml.snakeyaml.LoaderOptions;
2425
import org.yaml.snakeyaml.Yaml;
2526
import org.yaml.snakeyaml.constructor.SafeConstructor;
2627

@@ -32,6 +33,8 @@
3233
public class Parser {
3334

3435
private static final String REGEX_YAML_PATH = "/ua_parser/regexes.yaml";
36+
37+
public static final int CODE_POINT_LIMIT = 3455764;
3538
private UserAgentParser uaParser;
3639
private OSParser osParser;
3740
private DeviceParser deviceParser;
@@ -41,8 +44,18 @@ public class Parser {
4144
* @throws RuntimeException if there's a problem reading the file from the classpath
4245
*/
4346
public Parser() {
47+
this(getDefaultLoaderOptions());
48+
}
49+
50+
/**
51+
* Creates a parser using the regular expression yaml file bundled in the jar.
52+
*
53+
* @param loaderOptions configuration for loading parser safe limits.
54+
* @throws RuntimeException if there's a problem reading the file from the classpath.
55+
*/
56+
public Parser(LoaderOptions loaderOptions) {
4457
try (InputStream is = Parser.class.getResourceAsStream(REGEX_YAML_PATH)) {
45-
initialize(is);
58+
initialize(is, loaderOptions);
4659
} catch (IOException e) {
4760
throw new RuntimeException("failed to initialize parser from regexes.yaml bundled in jar", e);
4861
}
@@ -54,7 +67,16 @@ public Parser() {
5467
* @param regexYaml the yaml file containing the regular expressions
5568
*/
5669
public Parser(InputStream regexYaml) {
57-
initialize(regexYaml);
70+
this(regexYaml, getDefaultLoaderOptions());
71+
}
72+
/**
73+
* Creates a parser using the supplied regular expression yaml file.
74+
* It is the responsibility of the caller to close the InputStream after construction.
75+
* @param regexYaml the yaml file containing the regular expressions
76+
* @param loaderOptions configuration for loading parser safe limits.
77+
*/
78+
public Parser(InputStream regexYaml, LoaderOptions loaderOptions) {
79+
initialize(regexYaml, loaderOptions);
5880
}
5981

6082
public Client parse(String agentString) {
@@ -76,9 +98,15 @@ public OS parseOS(String agentString) {
7698
return osParser.parse(agentString);
7799
}
78100

79-
private void initialize(InputStream regexYaml) {
80-
Yaml yaml = new Yaml(new SafeConstructor());
81-
101+
public static LoaderOptions getDefaultLoaderOptions(){
102+
LoaderOptions options = new LoaderOptions();
103+
options.setCodePointLimit(CODE_POINT_LIMIT);
104+
return options;
105+
}
106+
107+
private void initialize(InputStream regexYaml, LoaderOptions loaderOptions) {
108+
Yaml yaml = new Yaml(new SafeConstructor(loaderOptions));
109+
82110
@SuppressWarnings("unchecked")
83111
Map<String,List<Map<String,String>>> regexConfig = (Map<String,List<Map<String,String>>>) yaml.load(regexYaml);
84112

src/test/java/ua_parser/ParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public class ParserTest {
3737
final String TEST_RESOURCE_PATH = "/ua_parser/";
38-
Yaml yaml = new Yaml();
38+
Yaml yaml = new Yaml(Parser.getDefaultLoaderOptions());;
3939
Parser parser;
4040

4141
@Before

0 commit comments

Comments
 (0)