Skip to content

Commit

Permalink
fix (kubernetes-client-api) : Change SnakeYaml's implicit resolver me…
Browse files Browse the repository at this point in the history
…thod signature

We don't seem to have any direct dependency on SnakeYaml. It's coming as
transitive dependency from Jackson Dataformat Yaml.

In Jackson 2.13.3 SnakeYaml 1.30 was being used. In 2.13.4, SnakeYaml
1.31 is getting used which seems to have some changes with respect to
resolvers limits. Modifying CustomYamlTagResolver used in serialization
with respect to new version.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia authored and manusa committed Sep 9, 2022
1 parent d483aa4 commit 0742e94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 10 additions & 0 deletions kubernetes-client-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,19 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ private static <T> T unmarshal(InputStream is, ObjectMapper mapper, TypeReferenc

final T result;
if (intch != '{') {
final Yaml yaml = new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), new CustomYamlTagResolver());
final Yaml yaml = new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(),
new CustomYamlTagResolverWithLimit());
final Map<String, Object> obj = yaml.load(bis);
result = mapper.convertValue(obj, type);
} else {
Expand Down Expand Up @@ -426,16 +427,16 @@ public static <T> T clone(T resource) {
}
}

private static class CustomYamlTagResolver extends Resolver {
private static class CustomYamlTagResolverWithLimit extends Resolver {
@Override
public void addImplicitResolver(Tag tag, Pattern regexp, String first) {
public void addImplicitResolver(Tag tag, Pattern regexp, String first, int limit) {
if (tag == Tag.TIMESTAMP)
return;
if (tag.equals(Tag.BOOL)) {
regexp = Pattern.compile("^(?:true|True|TRUE|false|False|FALSE)$");
first = "tTfF";
}
super.addImplicitResolver(tag, regexp, first);
super.addImplicitResolver(tag, regexp, first, limit);
}
}
}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@
<type>pom</type>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>

<!-- Dependencies -->
<dependency>
<groupId>io.sundr</groupId>
Expand Down

0 comments on commit 0742e94

Please sign in to comment.